Answer Posted / amit singh
in java all function are virtual.only the function marked
with the final is not virtual.
means to say that if there is any method in super class and
you implemented this method in subclasses too.
then you can invoke on any subcalsses instances refer to
as a superclasses.and the method behaviour will change
according to subcallses instances .
class Amit
{
public void sleep()
{
System.out.println("amit slleping");
}
public static void main(String []args)
{
Amit a = new Amit();
a.sleep();
a = new Subclass1();
a.sleep();
a= new Subclass2();
a.sleep();
}
}
class Subclass1 extends Amit
{
public void sleep()
{
Sysetm.out.println("subclass sleeping");
}
}
class Subclass1 extends Amit
{
public void sleep()
{
System.out.println("subclass 2 sleeping");
}
}
so the output will be
amit sleeping
Subclass1 sleeping
Subclass2 sleeping
so the eat function behave virtualy for the differnt
instance .so this is called the virtual function .so don't
worry every function in java are virtual not the final
function.
| Is This Answer Correct ? | 5 Yes | 0 No |
Post New Answer View All Answers
Explain static nested classes ?
What is boolean flag in java?
What about method local inner classes or local inner classes in java?
Can you sort a list in java?
Explain the difference between comparator and comparable in java?
What is internal variable?
Why does the integer quotient -0/3 yield 0, but the double quotient -0.0/3.0 yields – 0.0?
Do I need java for windows 10?
Give me an example of array and linked list? Where they can be used?
What does this mean java?
What is the file extension for java?
How do you invoke a method?
Explain about exception propagation?
Can we override the private methods?
Is vector ordered in java?