can any one tell me when do u go for inheritance and
polymorphism
Answers were Sorted based on User's Feedback
Answer / ganesh
Inheritance :
If you want to reuse the existing class
characteristics(methods,variables ..) then you will use
inheritance ..
Polymorphism :
If you want a method to respond based on our requirement
then we will use polymorphism ..for example like swapping
two variables is same for all types but if write program
means for different types(int,double,char..) u need to write
different methods but under a common method name..
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / krish
Inheritance:Your are in a situation where you have to the
properties of a whole class repeatedly then you can go for
inheritance.
Note:Final class can't be inherited.
Polymorphism:When you are in a situation where you need to
use a method repeatedly then you can go for polymorphism.
Eg:
consider this method
add(int i,int j) and add(String s1,String s2)
the former will add two integers and later will concatenate
two strings but both using the same method name.
Is This Answer Correct ? | 1 Yes | 1 No |
Answer / kishor kommulas
Inheritance:::
If you want to make use of the functionality of the method,
which is already there then you can go for the inheritance.
Polymorphism::::
If you want to use the same method name for different
method,then you can go for Polymorphism.
Is This Answer Correct ? | 0 Yes | 0 No |
Explain how hashmap works?
How to override equals() and hashCode() method in java?
What is an event?
what are the new features available in java 1.5 version?
3 Answers Accenture, Features, Motorola,
What is the difference between int and integer in java?
What is the use of inner class?
WAP to illustrate the use of interface
Suppose there is an Online shopping cart application having different objects like Cart, SelectionItem, Billing, COnfiguration, Authentication, Authorization, PersonalDetails etc. Out of this which one can be made a singleton pattern and why?
What is the difference between a public and a non-public class?
Can we convert stringbuilder to string in java?
How do you call a reference in java?
How many bytes is a string java?