can any one tell me when do u go for inheritance and
polymorphism

Answers were Sorted based on User's Feedback



can any one tell me when do u go for inheritance and polymorphism..

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

can any one tell me when do u go for inheritance and polymorphism..

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

can any one tell me when do u go for inheritance and polymorphism..

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

Post New Answer

More Core Java Interview Questions

Explain java coding standards for constants?

0 Answers  


What is complexity in java?

0 Answers  


Define how objects are stored in java?

0 Answers  


Does windows 10 need java?

0 Answers  


Detail discussions on JVM, memory management and garbage collector.

0 Answers   Expedia,


Can a private method of a superclass be declared within a subclass?

0 Answers  


Given a singly linked list, determine whether it contains a loop or not without using temporary space?

0 Answers   Global Logic,


what is meant by string pooling?

12 Answers   Oracle, Polaris, Tribal Fusion, Wipro,


How can we handle runtime exceptions? write one sample program? Can we write runtime exceptions beside the throws key word? if yes write sample program?

1 Answers   Huawei,


What is nullpointerexception in java?

0 Answers  


when to for abstract class and when to go for interface

2 Answers  


Explain the differences between public, private, protected and static?

4 Answers  


Categories