What are the ways of polymorphism other than Overridding &
Overloading



What are the ways of polymorphism other than Overridding & Overloading..

Answer / alka

Interface is third way to achieve polymorphism.Because when
you call a method on any interface variable then at run time
it is decided which object method to call.
Ex :
Let there is a Interface A:
public interface A
{
void display();
}

And two classes B and C implement A
class B implements A
{
display()
{
System.out.println("Class B");
}
}

class C implements A
{
display()
{
System.out.println("Class C");
}
}

Then while using interface A..see what will happen
class mainClass
{
public static void main(String args[])
{
A obj = new C();
obj.display();
obj = new B();
obj.display();
}
}

Output : Class C
Class B
So it is clear that while run/execution time it is decided
which display() method to call..i.e class B or class C display()

Is This Answer Correct ?    17 Yes 0 No

Post New Answer

More Core Java Interview Questions

What is concurrent hashmap and its features?

0 Answers  


Can u write constructor in abstract.If yes den when it will be invoked.

4 Answers   SunGard,


What are different types of encoding?

0 Answers  


Why is singleton instance static?

0 Answers  


Is java 1.7 the same as java 7?

0 Answers  






can u override the start() method of Thread class

5 Answers  


system.out.println(1 + 3);

8 Answers  


what should do when using multiple catch() block & what should never do for the same?

1 Answers  


Why do we create threads in java?

0 Answers  


Why null value is used in string?

0 Answers  


How many types of variables are there?

0 Answers  


Have you worked on bits programming? examples?What is bit? How many bits are there in the byte?

1 Answers  


Categories