Example5_2(子类对象的构造方法)

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);
 }
}
public class Example5_2{
 public static void main(String arg[]){
  B b=new B();
  b.g();
  b.f();
  b.g();
 }
}

原文地址:https://www.cnblogs.com/wangchunmeix/p/3020700.html