aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Forward reference 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 "Forward reference" Watch "Forward reference" New topic
Author

Forward reference

Srinivas Kumar
Ranch Hand

Joined: Jul 14, 2005
Posts: 52
public class AQuestion
{
private int i = j;
private int j = 10;
public static void main(String args[])
{
System.out.println((new AQuestion()).i);
}
}

Answers

a)Compiler error complaining about access restriction of private variables of AQuestion.
b)Compiler error complaining about forward referencing.
c)No error - The output is 0;
d)No error - The output is 10;

answer is given as b.
can anybody explain?
Srinivas Kumar
Ranch Hand

Joined: Jul 14, 2005
Posts: 52
Got the answer from the following link
http://radio.javaranch.com/corey/2004/05/13/1084483439000.html
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

See Corey's Tipline on Forward Referencing.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
jQuery in Action, 2nd edition
 
subject: Forward reference