0
추상 클래스의 서브 클래스에서 인스턴스화 된 객체에 액세스하고 싶습니다. 여기에 예제가 있습니다.Java의 추상 클래스의 서브 클래스에서 인스턴스화 된 객체에 어떻게 액세스합니까?
// A.java
public abstract class A {
public int getNewNo() {
int newNo = <Instance of B in this example here>.getNo() + 2;
return newNo;
}
}
// B.java
public class B extends A {
public int getNo() {
return 2;
}
}
// C.java
public class C {
public C(A a) {
System.out.println("The number is "+a.getNewNo());
}
}
// example.java
public void main(String args[]) {
B b = new B();
C c = new C(b);
// should now print out "The number is 4"
}
이게 가능합니까?
감사합니다.
당신은 초 만에 나를 때린다. – Reddy
@ Reddy 그리고 당신은 체크 표시가있다. 무슨 세상, 무슨 세상 :) – sje397