Ash Gill wrote:hi everyone, i have a small doubt. Given the following code:
can we say that class TestIt has-a Animal and class TestIt has-a Dog?
thanks
OCPJP 6
Ash Gill wrote:hi everyone, i have a small doubt. Given the following code:
can we say that class TestIt has-a Animal and class TestIt has-a Dog?
thanks
``Worry does not empty tomorrow of its sorrow; it empties today of its strength.''
Hama Kamal wrote:
Ash Gill wrote:hi everyone, i have a small doubt. Given the following code:
can we say that class TestIt has-a Animal and class TestIt has-a Dog?
thanks
Hi Ash,
i thinak we can say that , since TestIt has a reference to class Animal so TestIt has-a Animal and since Dog is-a Animal so TestIt has-a Dog as well....please correct me if you think i'm wrong!
OCPJP 6
Boris Mechkov wrote:
Hama Kamal wrote:
Ash Gill wrote:hi everyone, i have a small doubt. Given the following code:
can we say that class TestIt has-a Animal and class TestIt has-a Dog?
thanks
Hi Ash,
i thinak we can say that , since TestIt has a reference to class Animal so TestIt has-a Animal and since Dog is-a Animal so TestIt has-a Dog as well....please correct me if you think i'm wrong!
Hama,
you cannot say that TestIt HAS-A animal, nor a Dog. The reference is declared in the main() method, so HAS-A is not valid here. HAS-A is related to instance variables only (variables declared outside a method declarations, but within the class declaration)
``Worry does not empty tomorrow of its sorrow; it empties today of its strength.''
Hama Kamal wrote:
Boris Mechkov wrote:
Hama Kamal wrote:
Ash Gill wrote:hi everyone, i have a small doubt. Given the following code:
can we say that class TestIt has-a Animal and class TestIt has-a Dog?
thanks
Hi Ash,
i thinak we can say that , since TestIt has a reference to class Animal so TestIt has-a Animal and since Dog is-a Animal so TestIt has-a Dog as well....please correct me if you think i'm wrong!
Hama,
you cannot say that TestIt HAS-A animal, nor a Dog. The reference is declared in the main() method, so HAS-A is not valid here. HAS-A is related to instance variables only (variables declared outside a method declarations, but within the class declaration)
Hi Boris
you are right i've already corrected my statement in the above post.
OCPJP 6
Ash Gill wrote:Hi Boris, thanks for the explanation. one more doubt, Does the Has-a relation work in case of static references, like in line ##1 below?
OCPJP 6
Hama Kamal wrote:
Ash Gill wrote:hi everyone, i have a small doubt. Given the following code:
can we say that class TestIt has-a Animal and class TestIt has-a Dog?
thanks
Hi Ash,
i think we could say that if it was instance variable , since TestIt has a reference to class Animal so TestIt has-a Animal and since Dog is-a Animal so TestIt has-a Dog as well....please correct me if you think i'm wrong!
Ash Gill wrote:
Hama Kamal wrote:
Ash Gill wrote:hi everyone, i have a small doubt. Given the following code:
can we say that class TestIt has-a Animal and class TestIt has-a Dog?
thanks
Hi Ash,
i think we could say that if it was instance variable , since TestIt has a reference to class Animal so TestIt has-a Animal and since Dog is-a Animal so TestIt has-a Dog as well....please correct me if you think i'm wrong!
hi Hama, thanks. i now understand that if 'a' was an instance variable then TestIt definately Has-A Animal but i m still doubtful about TestIt having a dog.
OCPJP 6
``Worry does not empty tomorrow of its sorrow; it empties today of its strength.''
Hama Kamal wrote:so do you guys mean that
TestIt has-a Animal true
TestIt has-a Dog false ?
OCPJP 6
``Worry does not empty tomorrow of its sorrow; it empties today of its strength.''
Hama Kamal wrote:but if it was like
we could say that
TestIt has-a Dog and TestIt has-a Animal >>> since we can access all the members of Animal class through object reference variable g .... am i right?
OCPJP 6
Boris Mechkov wrote:
Hama Kamal wrote:but if it was like
we could say that
TestIt has-a Dog and TestIt has-a Animal >>> since we can access all the members of Animal class through object reference variable g .... am i right?
My understanding is that when we say HAS-A means whether a class HAS an instance reference to another class. So, to answer your question, i would say that testIt HAS-A Dog, but TestIt does not have an Animal. Dog itself IS-A Animal, but the reference that TestIt has is a DOG reference, so TestIt HAS-A Dog.
``Worry does not empty tomorrow of its sorrow; it empties today of its strength.''
Hama Kamal wrote:
Boris Mechkov wrote:
Hama Kamal wrote:but if it was like
we could say that
TestIt has-a Dog and TestIt has-a Animal >>> since we can access all the members of Animal class through object reference variable g .... am i right?
My understanding is that when we say HAS-A means whether a class HAS an instance reference to another class. So, to answer your question, i would say that testIt HAS-A Dog, but TestIt does not have an Animal. Dog itself IS-A Animal, but the reference that TestIt has is a DOG reference, so TestIt HAS-A Dog.
well i don't know really know, let's take someone else's idea about this issue,,,,, but one more thing
are you sure that in the below code
TestIt has-a Animal is wrong?! because as i searched some documents i couldn't find that !! it only says that if a class has a rference to another class then it has it ,, it does not say that it shoud be declared outside of the method body,,, my point is are you absolutely sure about that? becasue im not,,, thanks
OCPJP 6
What book are you using to study? Kathy and Bert's book on SCJP6 is the best out there.
``Worry does not empty tomorrow of its sorrow; it empties today of its strength.''
Ash Gill wrote:thanks Boris and Hama, so
Has-A relationship only applies to static or instance variables of a class &
Has-A has to do with the reference type of the object and not the actual object type.
``Worry does not empty tomorrow of its sorrow; it empties today of its strength.''
Boris Mechkov wrote:
Hama Kamal wrote:
Ash Gill wrote:hi everyone, i have a small doubt. Given the following code:
can we say that class TestIt has-a Animal and class TestIt has-a Dog?
thanks
Hi Ash,
i thinak we can say that , since TestIt has a reference to class Animal so TestIt has-a Animal and since Dog is-a Animal so TestIt has-a Dog as well....please correct me if you think i'm wrong!
Hama,
you cannot say that TestIt HAS-A animal, nor a Dog. The reference is declared in the main() method, so HAS-A is not valid here. HAS-A is related to instance variables only (variables declared outside a method declarations, but within the class declaration)