java 如何pass reference to it??????????
class A{
A(){
System.out.println( "in A 's constructor ");
}
void set(){
}
public static void main(String[] args){
A a=new A();
B b=new B();
b.do();
}
}
class B{
do(){
//在B里如何调用set()??????????????????
}
}
------解决方案--------------------class A{
A(){
System.out.println( "in A 's constructor ");
}
void set(){
}
public static void main(String[] args){
A a=new A();
B b=new B(a);
b.do();
}
}
class B{
A a = null;
B(A a){
this.a = a;
}
do(){
a.set();//在B里如何调用set()??????????????????
}
}
------解决方案--------------------class A{
A(){
System.out.println( "in A 's constructor ");
}
void set(){
}
public static void main(String[] args){
A a=new A();
B b=new B();
b.do(a);
}
}
class B{
do(A a){
//在B里如何调用set()??????????????????
a.set();
}
}