aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Static block Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Static block" Watch "Static block" New topic
Author

Static block

George Fung
Ranch Hand

Joined: Jun 12, 2003
Posts: 98
static init blocks are executed at class loading time, so I think it shows "b1" first. Why it display "r1" at the beginning?

class Bird {
{ System.out.print("b1 "); }
public Bird() { System.out.print("b2 "); }
}
class Raptor extends Bird {
static { System.out.print("r1 "); }
public Raptor() { System.out.print("r2 "); }
{ System.out.print("r3 "); }
static { System.out.print("r4 "); }
}
class Hawk extends Raptor {
public static void main(String[] args) {
System.out.print("pre ");
new Hawk();
System.out.println("hawk ");
}
}
What is the result?
r1 r4 pre b1 b2 r3 r2 hawk

SCJP, SCJD, SCWCD, SCBCD, SCEA, SCJP6
To be obtained: SCEA 5
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
is println("b1") in a static block? I don't think so -- where's the static keyword?
George Fung
Ranch Hand

Joined: Jun 12, 2003
Posts: 98
Thanks a lot.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Static block
 
Similar Threads
Please explian the output ....
Initialization blocks...
11 K&B questions. Question 3
Problem in understanding output of Program
Please explain the output