aspose file tools*
The moose likes Beginning Java and the fly likes Can someone explain this output? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Can someone explain this output?" Watch "Can someone explain this output?" New topic
Author

Can someone explain this output?

Ronald Gans
Greenhorn

Joined: Jul 11, 2009
Posts: 1
public class Parent {
{
System.out.println("1");
}
static {
System.out.println("6");
}

public Parent(String greeting) {
System.out.println("2");
}

public Parent()
{
System.out.println("5");
}

public static void main(String [] args) {
//Parent p = new Parent();
Child c = new Child();
}

}

class Child extends Parent {
static {
System.out.println("3");
}

{
System.out.println("4");
}
}

output is
6
3
1
5
4
Jason Irwin
Ranch Hand

Joined: Jun 09, 2009
Posts: 327
Read this this post and this post (link provided by Jeetendra).

They should explain it.


SCJP6
 
Don't get me started about those stupid light bulbs.
 
subject: Can someone explain this output?