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

What is parsing a string?

586


What environment variables are required to be set on a machine in order to run Java programs?

612


What happens if an exception is not handled in a program?

620


What is size of int in java?

541


What are access specifiers in java ?

587






What is jvm? Why is java called the platform independent programming language?

539


What is a nonetype?

559


Why java is used everywhere?

584


How hashmap works in java?

558


What is a qualifier in a sentence?

518


When will you define a method as static in Java?

560


Explain about abstract classes in java?

577


Describe how to implement singleton design pattern in struts.

523


What is stream api in java8?

531


What are identifiers in java?

571