This week's book giveaway is in the iOS forum.
We're giving away four copies of Classic Computer Science Problems in Swift and have David Kopec on-line!
See this thread for details.
Win a copy of Classic Computer Science Problems in Swift this week in the iOS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

anglefire.com question  RSS feed

 
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read the following code excerpt carefully. //Contents of file A.java public


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
Answer are 4 and 5.

6.My question is when I run the program in the command line and listed how many class files are there? to get the answer 4.I got only one class file created.But here,how come the answer �Two class files corresponding to both inner classes (B) is created in the file system.�-is coming?Can anyone please explain?
 
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the inner "B" classes. Ok You have defined one B class definition. the sections of code



and


are anonymous inner classes that extend from B.

Read inner classes from thinking in java.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please can you tell us the exact url to these angelfire.com questions?
 
Shiva Mohan
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sorry to get back this late.
The exact URL is
http://www.angelfire.com/or/abhilash/Main.html

Over there,we can find 9 quizes.
 
Ranch Hand
Posts: 1249
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Then you will get output as

"I am in the arg constructor"

and if we are using class C as follows:



this time no output is coming instead of
"I am in no-arg constructor"

Why this is coming so???
Should we discuss this in same thread or should we start a new thread...
??
[ July 25, 2006: Message edited by: Ankur Sharma ]
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because the no-arg constructor of class A doesnot create any instance of inner class B.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because the printing of the "I am in the (no)-arg constructors" messages are not in the (no)-arg constructors! They are in instance initialization blocks of the constructors' local inner classes.

I was going to edit this to add what Neelish wrote, but I need not bother now.
[ July 25, 2006: Message edited by: Barry Gaunt ]
 
Shaan Shar
Ranch Hand
Posts: 1249
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Barry Gaunt:
Because the printing of the "I am in the (no)-arg constructors" messages are not in the no-arg constructors! They are in instance initialization blocks of the constructors' local inner classes.



Oops...... I missed this line...






Well Thankx for reminding this line...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!