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 type of value does sizeof return?

779


What is java and its types?

779


What initialize variables?

716


How do you check if a character in a string is a digit or letter?

802


What are inbuilt functions in java?

797


Write a program to find the whether a number is an Armstrong number or not?

786


Is integer a class?

794


When do I need to use reflection feature in java?

829


How is a structure different from array ?

797


What is the purpose of the system class in java?

777


How do you sort in ascending order in java?

685


explain multi-threading in java?

792


What is field name?

779


What is a class in java?

799


What are parameters in a method?

805