This week's book giveaways are in the Scala and Android forums.
We're giving away four copies each of Machine Learning Systems: Designs that scale and Xamarin in Action: Creating native cross-platform mobile apps and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

constructors with inner classes.  RSS feed

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was stuck up at the following question from one of the mock exams.


Which of the following are true

1. A.java cannot be compiled. Duplicate defination of inner class B.

2. A.java compiles without any error. An attempt to run C as an application will cause runtime linkage error. Duplicate definations of inner class B are found

3. Only one class file corresponding to the inner class B is created in the file system.

4. Two class files corresponding to both inner classes (B) is created in the file system.

5. The classes compile cleanly and on running C as an application causes "I am in the arg constructor" to be printed on the console

Corredct Answer : 4 and 5.

I am satisfied with option 5.
Coming to option 4, the main method has the code A a = new A(1);
which executes the following code:

So how two class files corresponding to both inner classes (B) are created in the file system ?

Thanks in advance,
Rajani.

Edited by Corey McGlone: Added CODE Tags and Reformatted Code for Readability.
[ June 07, 2004: Message edited by: Corey McGlone ]
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just because a chunk of code is not executed does not mean it is not compiled. All of the code is compiled - both constructors. As each constructor contains a local class, a class file is generated for each local class. If you compile this code, you'll find that the following class files are generated:

A.class
A$1B.class
A$2b.class
C.class

Therefore, option 4 is correct.

However, this will not appear on the SCJP exam.
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It Should be :

A.class
A$1$B.class
A$2$B.class
C.class
 
Live a little! The night is young! And we have umbrellas in our drinks! This umbrella has a tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!