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 |
Can list contain null in java?
What is meant by object oriented programming – oop?
what questions are been asked ??? for interview in apti
What is CardLayout?
Is string is a data type in java?
Can we extend a class with private constructor?
What’s a deadlock?
What are "methods" and "fields"?
What is the relationship between clipping and repainting under awt?
which methods consisting of the serilizable interface?
What is garbage collection in Java, and how can it be used ?
32 Answers Accenture, HCL, Infosys, Sara, SITS, TCS, Wipro,
What are java annotations?