Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can someone explain this output?

 
Ronald Gans
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 327
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read this this post and this post (link provided by Jeetendra).

They should explain it.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic