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

constructor

 
meena latha
Ranch Hand
Posts: 219
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all

If we invoke a inner class using the instance of the outer class does the outer class constructor will also get invoked or not....

For example

Can anybody explain how many time A() is invoked.

Thanks In advance.
[ February 23, 2005: Message edited by: ramya jp ]
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Once.
 
Jay Pawar
Ranch Hand
Posts: 411
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ramya,
Simple test would be to put System.out.println statement in the constructor of the Outer class and observe the output.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ramya, you may like to try this variation of your code:
 
meena latha
Ranch Hand
Posts: 219
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all.
When u dont extend the class A then

line 1 will call the constructor of A.
Line 2 will invoke the constructor of B using an instance of A.
Line 3 does the same

But when we make
class B extends A
Then each time when we invoke the B() the superclass Constructor is also call.

I am not clear why this difference happens.Is it because only when we extend the B becomes the subclass of A.
If we dont extend then B is just a class inside a Class A and not a subclass.
Thanks in advance
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ramya wrote:
Is it because only when we extend the B becomes the subclass of A?
If we don't extend then B is just a class inside a Class A and not a subclass?


Exactly.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic