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


Please Help Members By Posting Answers For Below Questions

Can you instantiate the math class?

604


What exactly is a .class file?

581


How can you make a class serializable in java?

571


write a program that list all permutations of ABCDEF in which A appears before B?

2015


Can bool be null?

528






How can I debug the Java security exceptions and AccessControlExceptions?

640


What is a war file?

555


What is parameter example?

552


What about anonymous inner classes in java?

568


What is the final keyword denotes?

684


What is JDBC Driver interface?How can you retrieve data from the ResultSet

1515


what is singleton in java?

604


Can a class extends itself in java?

531


Is main a keyword in java?

542


What are the advantages of java?

516