Page 1 of 1

About Question enthuware.ocajp.i.v7.2.1160 :

Posted: Sat Sep 01, 2012 3:29 am
by ETS User
According to the question, I guess the classes should look like this:
MyClass
L--- OurClass
L---- YourClass

Since "OurClass contains a reference to YourClass" is correct according to the answer, why "MyClass contains a reference to OurClass" is wrong?

Re: About Question enthuware.ocajp.i.v7.2.1160 :

Posted: Sat Sep 01, 2012 3:31 am
by Guest
Edit:

MyClass
L--- OurClass
.......L---- YourClass

I thought that space will be displayed correctly. This is the updated one

Re: About Question enthuware.ocajp.i.v7.2.1160 :

Posted: Sat Sep 01, 2012 6:54 am
by admin
OurClass is a MyClass that means OurClass extends MyClass.
OurClass has a YourClass object means, there is a field of class YourClass in OurClass.

MyClass doesn't contain a field of class YourClass, OurClass does.
classdia.jpg
classdia.jpg (10.96 KiB) Viewed 6103 times

Re: About Question enthuware.ocajp.i.v7.2.1160 :

Posted: Fri Mar 08, 2013 12:27 pm
by Sweetpin2
admin wrote:OurClass is a MyClass that means OurClass extends MyClass.
OurClass has a YourClass object means, there is a field of class YourClass in OurClass.

MyClass doesn't contain a field of class YourClass, OurClass does.
classdia.jpg

Just a small correction to explanation

OurClass is a MyClass => OurClass extends  (or inherits from) MyClass. Thus, option 4(it should be option 5) is correct.

OurClass has a YourClass => OurClass refers to (or contains a reference to ) YourClass object. Thus, option 5(it should be option 4) is correct.

Re: About Question enthuware.ocajp.i.v7.2.1160 :

Posted: Fri Aug 29, 2014 3:17 am
by fabbbb
OurClass contains a reference to MyClass
Isn't this correct in form of the super reference?

Re: About Question enthuware.ocajp.i.v7.2.1160 :

Posted: Fri Aug 29, 2014 7:23 pm
by admin
No, super is not a reference to a separate object of the super class. It is just a way to refer the members of same object but inherited from the super class.

Re: About Question enthuware.ocajp.i.v7.2.1160 :

Posted: Wed Nov 29, 2017 1:55 pm
by lagartija
is this the correct code for it?

class MyClass {}

class OurClass extends MyClass {
YourClass yourclass= new YourClass();
}

class YourClass {}

Re: About Question enthuware.ocajp.i.v7.2.1160 :

Posted: Wed Nov 29, 2017 9:41 pm
by admin
Yes, that is correct, lagartija.