This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

inner class

 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 317
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Muhammad Farooq
Ranch Hand
Posts: 356
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic