先看下面这个简单的程序:
class A{
int i,j;
void Showij()
{
System.out.println("i,j are:"+i+j);
}
}
class B extends A{
int k;
void Showk()
{
System.out.println("K is:"+k);
}
void Showsum()
{
System.out.println("i,j,k are"+(i+j+k));
}
}
class Show{
public static void main(String args[]){
A a=new A();
B b=new B();
//超类used by itself
a.i=20;
a.j=30
a.Showij();
System.out.println("Supperclass used by itself");
//子类的使用
b.i=40;
b.j=90;
b.k=12;
b.Showij();
b.Showk();
b.Showsum();
System.out.println("Subclass used");
}
}