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

How do you classify Dialog Box?

0 Answers   CGI,


what is mean by ooad? where we are using? can you tell me any real time example?

1 Answers   Eka Software,


What does @param args mean in java?

0 Answers  


How do you declare an empty string?

0 Answers  


What is the difference between heap and stack memory?

0 Answers  






Explain about core java?

0 Answers  


give an example for encapsulation?

0 Answers   Aspire,


Explain about member inner classes?

0 Answers  


Can we use return in constructor?

0 Answers  


what is meant by serialization?

7 Answers  


What happens when I use / and % with a negative numerator?

0 Answers  


What is difference between float and double?

0 Answers  


Categories