class A{
private int x=10;
protected int y=20;
void f(){
y=y+x;
System.out.printf("x=%d,y=%d\n",x,y);
}
}
class B extends A{
void g(){
y=y+1;
System.out.printf("y=%d\n",y);
}
}
class Example5_2{
public static void main(String args[]){
B b=new B();
b.g();
b.f();
b.g();
}
private int x=10;
protected int y=20;
void f(){
y=y+x;
System.out.printf("x=%d,y=%d\n",x,y);
}
}
class B extends A{
void g(){
y=y+1;
System.out.printf("y=%d\n",y);
}
}
class Example5_2{
public static void main(String args[]){
B b=new B();
b.g();
b.f();
b.g();
}
}
结果:
y=21
x=10,y=31
y=32