• 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

K&B Master Exam OO Concepts Question

 
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

Could you please explain why option D is correct in the below question :

What statement(s) is/are true ?

a) is-a relationships always rely on inheritance.
b) is-a relationships always rely on instance variables.
c) is-a relationships always require at least two class types.
d) is-a relationships always rely on polymorphism.
e) is-a relationships are always tightly coupled.

In my first attempt I chose A and C, but according to MasterExam explanation the correct answers are A, C and D.

I'm woundering why option D would be correct. As far as I know polymorphism applies only to instance methods, thus supposing you have a given class B that extends class A and both have the same static method called as doSomething() for example, polymorphism will not be applied when calling this method but I still have a is-a relationship.

Please let me explain by using code :


If you run the above code the output is : Message sent from within class A.

You can see that polymorphism wasn't applied here but I still have a IS-A relationship.

Can anyone please give your comments.

Thanks
 
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
wow, moment...you are wrong.
is-a isn't about static fields...you don't inherite the static method...

now its polymorphism...
output : Message sent from within class B
read K&B pg 147...
arno
 
Arno Reper
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ps : its always beter to acces static fields (oop speaking ) via 'Class.staticStuff' and not via 'ref.staticStuff'. but both are legal...

arno
 
Edisandro Bessa
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Arno,

Thanks for your reply.

As far as I know static members are inherited but CANNOT be overriden.

It's true that IS-A relationships always rely on inheritance but I don't think IS-A relationships ALWAYS rely on polymorphism.

If you check the below code, I removed the doSomething() method in class B and declared a variable of type B in main.

The code still compiles and runs fine, proving that doSomething() from class A was inherited.

That's the point I got confused : When using static members there's no polymorphism but I still have IS-A relationships.


[ April 09, 2006: Message edited by: Edisandro Bessa ]
 
author
Posts: 9050
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Edisandro -

I think you're on the right track here - as I look at this question I see more problems than just with answer D - I don't know what I was smokin' when I wrote that one :roll:

Sorry...added to the list.

Bert
 
Arno Reper
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Edissandro,

When you had doSomething'method in the B class, it just mask the doSomething in the A. It wasn't an override...so i think you can't say is-a relationship for static stuff, because static is about class and not instance.

Hummm...how could i explain. Normally you don't reach static code via an instance reference, but because B is-a A, and you can do something like
So the doSomething'method has nothing to do with the B object because its a A class's method , but 'b' is still a A.

What do you think here about?

arno
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Answer C think of the situation with the interfaces
Is it still correct
 
Edisandro Bessa
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I think you are correct.

That's why Bert post here he also found problems than just with the answer D.


Bert's post :
I think you're on the right track here - as I look at this question I see more problems than just with answer D - I don't know what I was smokin' when I wrote that one

 
reply
    Bookmark Topic Watch Topic
  • New Topic