• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

constructors with inner classes.

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It Should be :

A.class
A$1$B.class
A$2$B.class
C.class
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic