This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Forward reference" Watch "Forward reference" New topic

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);


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
marc weber

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
I agree. Here's the link:
subject: Forward reference
jQuery in Action, 3rd edition