Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

Can private method static?

0 Answers  


Does Java support multiple Inheritance?

12 Answers  


can we write two same methods in outer class and innerclass.

1 Answers   3i Infotech,


Can a class extend more than one class?

0 Answers  


Can we execute a program without main?

0 Answers  


What is command line used for?

0 Answers  


How to optimize the javac output?

0 Answers  


where final and static variable stored?

3 Answers  


How do you declare a string variable?

0 Answers  


what is mena by object block any what is the use of that

0 Answers   CGI,


What does system.gc() and runtime.gc() methods do?

0 Answers  


question on Thread synchronization

3 Answers   Huawei,


Categories