aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes static block and empty block inside any class. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "static block and empty block inside any class." Watch "static block and empty block inside any class." New topic
Author

static block and empty block inside any class.

vikram Kesav
Ranch Hand

Joined: Jul 11, 2008
Posts: 69
Hello Ranchers,

I am confused with the output of the programme.



Output:=

Foo static
Bar static
foo
Bar
foo
Bar

Thanks in advance.

Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3855

Some basic concepts for you to think:

Before java can execute any code those classes should be loaded in to JVM first. When a class is to be loaded if that class extends any other classe(s) those should be loaded prior to that (one at the top of the hierarchy will be loaded first and then down the hierarchy, in the order). When the class is loaded it's static initializers are run. And last when an instance of the class is created it's instance initializers are run in the order they appear in the class file. For a comprehensive explanation you may refer the JLS .

HTH.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Samrat Kakustam
Ranch Hand

Joined: May 21, 2009
Posts: 56
Hi,
Check the code I made, comment the lines 1 - 5 in any order, execute and check the output each time. Hope that helps some way.


SCJP 5.0
Bob Wheeler
Ranch Hand

Joined: Apr 24, 2009
Posts: 317


SCJP 6 - SCJD - SCWCD 5 - SCBCD 5
JavaEnterpriseEditionFaq - TomcatFaq
 
 
subject: static block and empty block inside any class.