• 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 classes

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all experts..

I am new to java ranch... I tried invoking the inner class constructor() inside the main class constructor and it worked properly.

How come?? I thought we need outer obj to create inner obj so the compilation might fail..

please send some explanation.

Thanks in advance.
 
Bartender
Posts: 2911
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Swati.

Welcome to java ranch.

I feel its better if you posted the code here.
 
salvin francis
Bartender
Posts: 2911
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
btw, tu mumbai chi aahes ka?
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please, all discussion in English.
 
swati aole
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

swati aole wrote:Hi all experts..

I am new to java ranch... I tried invoking the inner class constructor() inside the main class constructor and it worked properly.

How come?? I thought we need outer obj to create inner obj so the compilation might fail..

please send some explanation.

Thanks in advance.



here is the code:

class testC
{
testC(){
new inner();
}
public class inner{
void show(){}
}
}

I am invoking the inner class constructor inside the outer constructor and it compiled ... but we need an outer obj to create inner obj ... so how can we create the inner obj before outer constructor generated an outer obj..
Thanks.


no I am not from mumbai and it would be great if anybody could send some explanation on this topic..
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are calling the inner class constructor from the outer class constructor. When you get to that constructor, there is implicitly an instance of the outer class in existence: the one being created at the moment.
 
swati aole
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:You are calling the inner class constructor from the outer class constructor. When you get to that constructor, there is implicitly an instance of the outer class in existence: the one being created at the moment.



Thanks a lot Campbell.. I always thought that the object doesn't get created and initialized the memory space until the constructor code executed completely.. could you please provide some explanation about the object creation and memory allocation process in java?

Regards
swati
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, but there was a thread which discussed that recently, here. Joanne Neal quoted the Java™ Language Specification: this section. See whether that helps.
 
This cake looks terrible, but it tastes great! Now take a bite out of this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic