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 |
In Java list the methods that can be overridden?
Explain oops concepts in detail?
what methods would you overwrite in java.lang.object class?
Is char a data type in java?
There are 2 methods in a class. Both have the same method signature except for return types. Is this overloading or overriding or what is it?
What is serialization in java?
In java, how we can disallow serialization of variables?
What is flush () in java?
What is == in java?
What is sleep method?
What is a protected method?
What restrictions are placed on method overloading?