This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes inner class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "inner class" Watch "inner class" New topic
Author

inner class

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi!
This questiom is from Sun Guoqiao's Mock Exam:

What is the output of trying to compile and run the following code?
(Select one correct answer)

public class Test014 extends Object
{
public static void main(String args[])
{
System.out.println(Test014.Inner.j); //1
}
class Inner
{
final static int j = 10; //2
}
}

A: The code does not compile because of line //1.
B: The code does not compile because of line //2.
C: The code compiles and runs with output: 10.
D: The code compiles but cannot run.
The correct answer is C, but I believe that a inner class can not have a statics members, only static inner clas can have statics members. For this I think that the correct answer is B. Can someone explain me please.
thank you in advance.
Guoqiao Sun
Ranch Hand

Joined: Jul 18, 2001
Posts: 317
Hi, Jordi, as to question mock-exam-01-14, I have modified it as to the inner class definition. The reason I made this mistake is when I compiled the question, I used Forte 2.0 as my compiler. It didn't find the error without the static modifier. Vanitha Sugumaran and Jon Ellison have pointed out my error and I corrected after that.
Sorry for the confusion caused.
Regards,

------------------
Guoqiao Sun
Sun Certified Programmer for Java™ 2 Platform
try my mock exam¹² at my homepage.


Guoqiao Sun<br />SCJP2 SCWCD2<br />Creator of <a href="http://www.jiris.com/" target="_blank" rel="nofollow">www.jiris.com</a>, Java resource, mock exam, forum
Muhammad Farooq
Ranch Hand

Joined: May 08, 2001
Posts: 356
The non-static inner class can not have static variable, but they can declalre static final variable. The above code compiles and run and Print 10 - the option C. I am using JDK 1.3.
--Farooq
[This message has been edited by Muhammad Farooq (edited September 08, 2001).]


Muhammad Farooq<br />Sun Certified Programmer for Java 2 Platform<br />Oracle8i Certified Professional Database Administrator
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: inner class