public class Father {
Father(int x){
//print();
//this.print();
y=x;
}
int y;
public int identity=100;
public int x=0;
public void print(){
System.out.println("print method in Father");
System.out.println("Identity in method \"print\" in Father object "+identity);
}
}
-------------
public class Son extends Father{
private int identity=99;
int y=7;
Son(){
//this in Father in Son
super(9);
super.print();
this.print();
}
public void print(){
System.out.println("print method in Son");
System.out.println("Identity used \"super\"in method \"print\" in Son object :> "+super.identity);
System.out.println("\nIdentity used \"this\"in method \"print\" in Son object "+this.identity);
System.out.println("\nIdentity in method \"print\" in Son object "+identity);
System.out.println("Y in son "+y);
System.out.println("Y in Father "+super.y);
//super.print();
}
}
-------------
public class In {
public static void main(String[] args) {
//Father f= new Father();
System.out.println("-----Partition-----");
Son s=new Son();
System.out.println("-----Partition-----");
Father t=(Father)s;
t.print();
//IMatrix a=new Matrix();
//a
}
}
沒有留言:
張貼留言