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 |
Which is bigger float or double?
Can you run java program without main method?
What is the maximum size of hashmap in java?
What is the difference between Java Bean and Java Class.?
How strings are created in java?
Explain the use of sublass in a java program?
Why Wait and notify are kept in Object class although they are used only with Thread Class
2 Answers Global Logic, Saksoft,
What is the maximum size of array in java?
what is the output ? Math.floor(-2.1) a)2 b)-2 c)-3.0 d)0
why java does not contain pointers?
Explain the scope or life time of class variables or static variables?
Is empty list java?