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 are variable arguments or varargs?

579


What is collections framework?

587


What is the java virtual machine?

595


What exceptions occur during serialization?

621


Why can't you declare a class as protected?

604






What is the null?

550


Can you sort a string in java?

498


What are the Class Libraries ?

601


What is the common usage of serialization? What exceptions occur during serialization?

610


What is the program compilation process?

598


What ide should I use for java?

504


What is the purpose of nested class in java?

611


What is difference between filereader and bufferedreader?

539


What is data string?

505


What is the difference between length and length () in java?

535