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 an example of a constant variable?

824


What is purpose of applet programming?

936


How do I run java on windows?

814


What is a nullable field?

800


Explain about serializable interface in java?

794


How many return statement are allowed in a function?

690


What is string syntax?

849


Is array a class in java?

758


How do you implement polymorphism in our day to day life?

2992


What is the default value of byte datatype in java?

720


Why convert an applet to an application?

898


What is == mean?

771


What is the purpose of nested class in java?

843


Addition to previous section relative word 5th one was Putrid ans: rotten, also there was prob. in 1st section on bucket weight ans:10kg, also there was a prob. on train speed to find bridge length ans:800 mtrs.

1870


Highest level event class of the event-delegation model?

3743