코린이 자바 질문 좀 할게요 ㅠㅠ
조회수 506회
class A{
int a; }
class B{
int b;
}
public calss A{
public static void main(String[] args)
{
A a=new A();
B b=a.a;
}
}
잘은 못하지만 제가 궁금한 건 기본자료형 외에 자료형은 주소값? 참조값을 넣을 수 있다고 배웠습니다 . 근데 제가 궁금한 것은 B b에 a.a에 접근을 어떻게 하나요? a.a를 할때 참조값이 B b에 들어가는 건가요?
package org.helloworld.javahelloworld.generic;
class StudentInfo{
public int grade;
StudentInfo(int grade){this.grade=grade;}
}
class EmployeeInfo{
public int rank;
EmployeeInfo(int rank){this.rank=rank;}
}
class Person{
public Object info;
public Person(Object info) {this.info=info;}
}
public class GenericDemo {
public static void main(String[] args) {
Person p1 = new Person("사람");
EmployeeInfo ei = (EmployeeInfo)p1.info;//이 부분이 궁금합니다 잘못된 코드 인건 알지만 저렇게 대입할 수 있는 이유가 궁금해요
System.out.println(ei.rank);
}
}
댓글 입력