What do you meant by Runtime Polymorphism?

Answer Posted / swe

In runtime polymorphism ... the code is called at run time according to need or given conditions.

suppose there r two methods namely Add() one in super class and other is in sub class.both have the same name and same parameters.

so we have to choose that which method from them shld called at run time i.e. of super class or of sub class.by polymorphism we do that.

ex:-

class A

{

int add(){//code of the method}

//some other code

}

class B extends A

{

int add(){//code of the method}

//some other code

}

class AB

{

public static void main(String s[])

{

A ob1;

ob1 new A();

int i ob1.add();//will call the method of super class.

ob1 new B();// sub class's reference can be assigned to super class address but not vice versa.to do that we have to type cast the reference of the sub class in reference of the super class.

int j ob1.add();//will call the method of sub class

}

Is This Answer Correct ?    1 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How does the type system works when there is interoperability between a COM and .Net, i mean what exactly happens there

1555


How do i find out the number of parameters passed into function?

2196


a characteristic of a multiprogramming is? a.simultaneous exe of pgm instr 4m 2 appli b.concurrent processing of 2 r more prgms c.multiple cpu s d.all the abov

1668


Definition of Singleton Class? what is the Purpose of it? what is the advantage?

1576


qtp 9.2 14 days demo version was expired.I uninstalled how to reinstall this again

2340






how much fee for deccan soft institute .how to block seat for sandeep sir class reply soonnnn 

1642


how do find the user exit for selected feild whatis the process and can u plz explain it

1713


What is BASIS

1648


What are two of your strengths that you will bring to our QA/testing team?

1627


what will we require to build project with the help of oracle

1372


code for connection from windows forms to sql server

1695


1. How many jobs can we write in a single file? 2. How many maximum members can exist in a single partition data set(pds) in jcl?

1903


what are the differences between CONS, LIST, and APPEND

4748


1. Consider the following code in our example assembly language: ; an example bit of assembly code ROOT: W FATHER FATHER: W SON1 W SON2 SON1: W NIL W NIL ; ---------------------- SON2: W GRANDSON W NIL GRANDSON: W NIL W NIL NIL = 0 Assemble this code carefully following the two pass model, and show the symbol table at the point marked by the dashed line during each pass.

1806


Q1.Write a C program which asks the user for a number between 1 to 9 and shows the  number. If the user inputs a number out of the specified range, the program should  show an error and prompt the user for a valid input.

2264