Why Over riding is Run Time Polymorphism?

Answer Posted / umanath

This is (Run Time Polymorphism) called Dynamic binding.

for more depth see the bellow example

class A
{
public String msg = "message-A";
public void display()
{
System.out.println(msg);
}
}
class B extends A
{
public String msg = "message-B";
public void display()
{
System.out.println(msg);
}
}

class demo
{
public static void main(String as[])
{
A a = new B() //RUN TIME POLYMORFISM
a.display() //Since a is a object type of class B SO class
B sum
System.out.println("From Main: "+a.msg);
}
}

Out Put:
message-B
From Main: message-A

Is This Answer Correct ?    4 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is gui programming?

524


What two classes are used to read data only?

643


Can we have more than one package statement in the source file?

645


Can we catch more than one exception in single catch block?

604


What does java edition mean?

540






What is close method? How it's different from Finalize & Dispose?

567


What is an example of a boolean?

573


Can we restart a dead thread in java?

555


Is int a class in java?

531


Why is multiple inheritance not supported in java?

562


whar are the draw backs of programming lang step by step in Clang and next in C++ and next and in Java nad in .Net

1666


Explain the selection sort algorithm?

646


What does replaceall do in java?

491


Can we declare register variable as global?

517


Do you know how to reverse string in java?

586