can any one tell me when do u go for inheritance and
polymorphism
Answer Posted / 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 |
Post New Answer View All Answers
Why use string handling in Java?
1.IN CASE OF DYNAMIC METHOD DISPATCH WHY WE USE REFERENCE VARIABLE,WE CAN USE THE DIFFERENT DEFINED OBJECT DIRECTLY TO ACCESS THE DATA MEMBER AND MEMBER FUNCTION OF THAT RESPECTIVE CLASS?WHAT IS THE MAIN FUNCTION OF "REFERENCE VARIABLE" HERE?
When does an object becomes eligible for garbage collection in java?
How many bytes is double?
What are classloaders?
How to instantiate member inner class?
How many characters is 2 bytes?
How do you add an arraylist to an array in java?
What does ide stand for?
What is the protected method modifier?
Is static a singleton?
What is a function in java?
What is the mapping mechanism used by java to identify IDL language?
What is the difference between super class & sub class?
What is the purpose of garbage collection in java?