Re: Who can tell me the initialzing sequence of a java programe?



Jack Dowson wrote:
abstract class A{
int i;
abstract void getInfo();
void print(){
System.out.println("print() int abstract class");
}
} class B extends A{
void getInfo(){
System.out.println("abstract method:getInfo() is implemented");
System.out.println("i =" + i);
}
}
public class AbstractClassDemo{
public static void main(String[] args){
B b = new B();
b.print();
b.getInfo();
}
}

The result is:
print() int abstract class
abstract method:getInfo() is implemented
i =0

My question is considering that method print in abstract class A is not a static method,then what happened to create the first sentence of the result("print() int abstract class")?

The line b.print();

Non-static 'print()', called via the instance pointed to by 'b', which in turn was created by 'new B()'. QED.

--
Lew
.