My Saturday:
Gives:
Super Static 1
Super Static 2
Static 1
Static 2
Super Non Static 1
Super Non Static 2
Super Constructor
Non Static 1
Non Static 2
Constructor
Inside Main!
Super Non Static 1
Super Non Static 2
Super Constructor
Non Static 1
Non Static 2
Constructor
Do note that without the
It would be:
Inside Main!
Super Static 1
Super Static 2
Static 1
Static 2
Super Non Static 1
Super Non Static 2
Super Constructor
Non Static 1
Non Static 2
Constructor
This is just a fundamental thing- but it pays to review the fundamentals to the point where you don't even think about them.
Now, back to it...
class Foo {
{ System.out.println("Super Non Static 1");}
static{ System.out.println("Super Static 1");}
public int Bob = 7;
public static final Integer Sam = Integer.valueOf(10);
public static final int Ted = 3;
Foo(){
System.out.println("Super Constructor");
}
{ System.out.println("Super Non Static 2");}
static{ System.out.println("Super Static 2");}
}
class Bar extends Foo{
{ System.out.println("Non Static 1");}
static{ System.out.println("Static 1");}
Bar(){
System.out.println("Constructor");
}
{ System.out.println("Non Static 2");}
static{ System.out.println("Static 2");}
}
public class InitTest{
static Bar bq = new Bar();
public static void main(String[] args){
System.out.println("Inside Main!");
Bar b = new Bar();
}
}
Gives:
Super Static 1
Super Static 2
Static 1
Static 2
Super Non Static 1
Super Non Static 2
Super Constructor
Non Static 1
Non Static 2
Constructor
Inside Main!
Super Non Static 1
Super Non Static 2
Super Constructor
Non Static 1
Non Static 2
Constructor
Do note that without the
static Bar bq = new Bar();
It would be:
Inside Main!
Super Static 1
Super Static 2
Static 1
Static 2
Super Non Static 1
Super Non Static 2
Super Constructor
Non Static 1
Non Static 2
Constructor
This is just a fundamental thing- but it pays to review the fundamentals to the point where you don't even think about them.
Now, back to it...









