62,614
社区成员
发帖
与我相关
我的任务
分享
public class 可擦除重写的实验类 {
/**
* @param args
*/
public static void main(String args[])
{
B b1=new B(10,20);
b1.show();
A a1=new A(50,30,b1);
a1.edit(b1);
b1.show();
}
}
class A
{
int a,c;
B b;
public A(int a ,int c,B b)
{
this.a=a;
this.c=c;
this.b=b;
}
public void edit(B b){
b.a=20;
}
}
class B
{
int a,c;
public B(int a,int c)
{
this.a=a;
this.c=c;
System.out.println(this.a);
}
public void show(){
System.out.println(a+"");
}
}
我稍修改了一下,你体会体会