wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes A contradiction....(Kahlid Mughal & Sun Java Tutorial) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "A contradiction....(Kahlid Mughal & Sun Java Tutorial)" Watch "A contradiction....(Kahlid Mughal & Sun Java Tutorial)" New topic
Author

A contradiction....(Kahlid Mughal & Sun Java Tutorial)

Amit Das
Ranch Hand

Joined: Mar 05, 2005
Posts: 206
Hi all,

i thinkthat it's a contradiction, can anyone acknowledge......

From Sun Java Tutorial:click here to refer
The interesting feature about the relationship between these two classes is not that InnerClass is syntactically defined within EnclosingClass. Rather, it's that an instance of InnerClass can exist only within an instance of EnclosingClass


Form Khalid Mughal age 12 chapter 1
Java supports aggregation of objects by reference, since objects can't contain other objects explicitly


can any one plz bother to explain me that am i taking it in a write way or Khalid mughal means somthing else also........

thanx
amit
Amit Das
Ranch Hand

Joined: Mar 05, 2005
Posts: 206
Is this post not worth answering or have ppl not understood this....plz tell me so that i can elucidate, if required....
Amit Das
Ranch Hand

Joined: Mar 05, 2005
Posts: 206
ok let me put it in simple way.....
Can an object have an instance on another object inside that object....???

thanx
amit
Karthikeyan Varadarajan
Ranch Hand

Joined: Jul 04, 2002
Posts: 98
What you mean Object ?


CODE] public class Test
{

String name;

public Test ()
{
name ="VK"
}

public String getName()
{
return name
}
}[ [/CODE]

If Ur going to create a Test Object , It will create a String Object in the heap and store the reference in the variable 'name'. so we are going to store only Object reference in Objects not Object itself.


~With Smile<br />VK
Amit Das
Ranch Hand

Joined: Mar 05, 2005
Posts: 206
i think u've misunderstood the question .....plz refer to my initial post .........u've demonstrated an example of HAS-A (aggregation)relationship.
My question is can an object(lower case) have an instance of another object as said in Sun Java tutorial and cotradicted in Khalid Mughal.........

Plz understand the questuion and then reply to in Javaranch...........


thanx
amit
Rohan Kayan
Ranch Hand

Joined: Sep 17, 2004
Posts: 123
My question is can an object(lower case) have an instance of another object as said in Sun Java tutorial and cotradicted in Khalid Mughal.........



An object can't have the another object , but it can have the reference to the another object . You can think like this , for creating any object of inner class you need an enclosing class's instance, this doesn't tell that that enclosing class hold the instance of inner class .


SCWCD 1.4, SCJP 1.4
Amit Das
Ranch Hand

Joined: Mar 05, 2005
Posts: 206
hi Rohan,

first of all i'd like to thank you for replying this post...........
secondly, i'd like to say that whatever u say is i understand and i agree, but can you just go through the link i have provided Sun Java Tutorial and scroll down to this :
Rather, it's that an instance of InnerClass can exist only within an instance of EnclosingClass

and don't forget to see the diagramatic representation of inner classes there

cheers!!!
amit
reubin haz
Ranch Hand

Joined: May 12, 2005
Posts: 287
I think when that Sun Java Tutorial speaks about 'an instance of InnerClass can exist only within an instance of EnclosingClass' and the diagram representation of inner classes, the author is trying to say outer class contains reference of InnerClass. There is no contradiction about containing an inner class when we say inner class's reference is contained in outer class. Only from outer class, the reference would allow us to access to inner class. If no container, as outer class, there will be no inner class, because only the inner class's reference reside in container, outer class, tells us where to look from for the inner class.


SCJA, SCJP5.0, SCBCD, SCWCD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A contradiction....(Kahlid Mughal & Sun Java Tutorial)