Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


Why Over riding is Run Time Polymorphism?

Answers were Sorted based on User's Feedback



Why Over riding is Run Time Polymorphism?..

Answer / anjani kumar jha

It is very diffcult for compiler to know which version of
the method called(superclass or subclass).

Hence to identify which version of method is called java
used run-time polymorphism(same copy used in both class)
where object type defined which version is called.
I am giving u one example............

class A
{
public void sum() //this is method which we will override
{
//some operation here//
}
}
class B extends A
{
public void sum() //over-riden method,see both method
r //same
{
//some operation here//
}
public static void main(String as[])
{
A a=new B() //RUN TIME POLYMORFISM
a.sum()//Since a is a object type of class B SO class B sum
method will be called................................
}
}
//I think uy doubt will be clear
}

Thanks and Regards
Anjani Kumar Jha
CDAC
9623154095

Is This Answer Correct ?    15 Yes 1 No

Why Over riding is Run Time Polymorphism?..

Answer / mani

Overriding method resolution always take care by JVM based
on runtime object. Hence overriding is consider as runtime
or dynamic orlatebinding.

Is This Answer Correct ?    16 Yes 3 No

Why Over riding is Run Time Polymorphism?..

Answer / 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

More Core Java Interview Questions

How is final different from finally and finalize?

0 Answers  


what is daemon thread and which method is used to create the daemon thread? : Java thread

0 Answers  


can rmi and corba based applications interact ?

0 Answers  


What is the implementation of destroy method in java. Is it native or java code?

0 Answers  


what is mean by String and StringBuffer? What is mean by Methooverriding and Overloading?

3 Answers   Satyam, STI,


Give a brief description of java socket programming?

0 Answers  


What is meant by Encapsulation? Can you write a class to explain encapsulation?

8 Answers   Ness Technologies,


How do you implement tree mirroring in java?

0 Answers   EXL, HCL,


What is instance means in java?

0 Answers  


What is functional interface in java?

0 Answers  


Can constructor be synchronized?

0 Answers  


How do you declare an infinite loop?

2 Answers  


Categories