File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "inner class" Watch "inner class" New topic

inner class

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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.

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="" target="_blank" rel="nofollow"></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.
[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:
subject: inner class
It's not a secret anymore!