wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes FAQ - Traps Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "FAQ - Traps" Watch "FAQ - Traps" New topic
Author

FAQ - Traps

vidhya Ramachandran
Greenhorn

Joined: Sep 15, 2000
Posts: 13

Can somebody give an eg for the following:
1.Forward references to variables gives compiler error.
2.Instance initializer(s) gets executed ONLY IF the objects are constructed.
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3255
    
    2
public class TestClass
{
 static{ System.out.println(" in static block"); }
 { System.out.println(" in non static block"); }
 public static void main(String args[])
 {
  // i = 10; //will give compile time error.
  // int i;
  //new TestClass(); //"in non-static block" will not be printed.
 }
}
HTH,
Paul.

------------------
Get Certified, Guaranteed!
http://www.enthuware.com/jqplus


Enthuware - Best Mock Exams and Questions for Oracle/Sun Java Certifications
Quality Guaranteed - Pass or Full Refund!
Mapraputa Is
Leverager of our synergies
Sheriff

Joined: Aug 26, 2000
Posts: 10065
1.Forward references to variables gives compiler error.
Paul gave an example.
To be nit-picky and confuse you more, I'll give an example when they do not give compiler error.

this code compiles because static vars are initizlized before instance vars, so forward reference instanceVar = staticVar is legal.


Uncontrolled vocabularies
"I try my best to make *all* my posts nice, even when I feel upset" -- Philippe Maquet
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: FAQ - Traps
 
Similar Threads
Clarify... Math Functions....
confusion in transient
WA #2 ..... word association
Scrabble... it only takes a minute...
what is mean by Encapsulation in OOPS?