• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

inner class

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic