This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of TensorFlow 2.0 in Action and have Thushan Ganegedara on-line!
See this thread for details.
Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

T/F: IS-A relationships always rely on polymorphism

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
true-- from the LearnKey exam.

Is this ALWAYS true? What if you have a class B that extends class A and they don't have any instance methods/vars--only static. Isn't there technically still an IS-A relationship between the classes with no chance of polymorphism?
 
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

What if you have a class B that extends class A and they don't have any instance methods/vars--only static.



If class B extends class A, they have a polymorphic relationship regardless of the methods they implement.

Instance methods or fields are not relevant to whether two classes have an IS-A relationship. It's a class-level concept.

IS-A relationships are implemented in Java by extending a class or implementing an interface.


Isn't there technically still an IS-A relationship between the classes with no chance of polymorphism?



Objects with an IS-A relationship are polymorphic. You won't have objects with an IS-A relationship and not also have polymorphism.
[ September 03, 2006: Message edited by: Scott Johnson ]
 
Dave Reinhardt
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's my understanding that polymorphism is specifically when a super class reference refers to a sub class object. The runtime machine can polymorphically call the correct instance method based on the actual object. However, it seems to me that you could have this inheritance structure between two classes that have only static methods and there will be no polymorphism

So inheritance (IS-A relationships) are not always polymorphic. Amy I wrong about this?
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you look for Polymorphism in this reference from Sun, you will see that only the IS-A relationship counts. You can use a object of a subclass in place of an object of the base class. There is no mention of the overriding of methods in this definition of polymorphism.

But in the JLS the only reference to polymorphism I found was referring to the overriding capability, that is calling a method on a reference to the base class being redirected to the overriding method in the subclass.

Perhaps the question would have been better as "Polymophism always depends on the IS-A relationship - true or false?"
 
Dave Reinhardt
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<Perhaps the question would have been better as "Polymophism always depends on the IS-A relationship - true or false?">

I can get behind this being true, but not the reverse.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What if you have a class B that extends class A and they don't have any instance methods/vars--only static.

It is a good question. But let me ask you something first, what is the reason for class B to extend class A? As far as i know If you extend a class, then you wish to say to JVM that you already have some functions in a class A which you wish to override in class B. If you don't want any methods to be overriden the entire concept of extending that particular class will be of no use.
 
Dave Reinhardt
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jegon,

That's a good point you make, but I was just trying to point out that you _could_ have an IS-A relationship in terms of Class B extending class A and have no possibility of polymorphism. So technically, the way I read the answer it is false.

That's the trouble with some of the questions that _should_ be easy questions on the exam. It's easy to write an ambiguous question about cohesion, or coupling, or polymorphism. I've come across several situations in the mock exams. Unfortunately, I read the questions very literally and then get the answer wrong. I would have phrased it as:

IS-A relationships usually rely on polymorphism
 
Then YOU must do the pig's work! Read this tiny ad. READ IT!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic