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

When do we need to use internal iteration? When do we need to use external iteration?

602


What is percentage in java?

568


What is the same as procedures?

527


What exceptions occur during serialization?

602


Difference between string, string builder, and string buffer?

521






How do you invoke a method?

537


Can we force garbage collector to run ?

566


How is it possible for two string objects with identical values not to be equal under the == operator?

521


What is the meaning of nullable?

572


How does multithreading take place on a computer with a single cpu in java programming?

522


What is difference between variable declaration and definition?

507


What is your platform?s default character encoding and how to know this?

1748


What are the special characters?

531


What are different types of expressions?

547


What is abstraction in java?

613