This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Forwrad Referncing 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 "Forwrad Referncing" Watch "Forwrad Referncing" New topic
Author

Forwrad Referncing

nishant vats
Greenhorn

Joined: Feb 11, 2005
Posts: 23
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 b

Q2)public class AQuestion
{
private int i = giveMeJ();
private int j = 10;

private int giveMeJ()
{
return j;
}

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 Compilation error - The output is 0;
d) No Compilation error - The output is 10;

Answer c

these are 2 questions i found in one of the mock exams.The first once answer is b.i thgt the second onces answer would also be b.But its c.Please do explain why the answer for the 2nd question is c.
Animesh Shrivastava
Ranch Hand

Joined: Jul 19, 2004
Posts: 298
Nishant,
Please look at the following post:
initialization
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Forwrad Referncing
 
Similar Threads
Angelfire.com....quiz 2
Angelfire.com....quiz 2
from abhilash's quiz
forward referencing doubt
Access Modifiers