some one give d clear explanation for polymorphism

Answer Posted / anjani kumar jha

Java supports two types of polymorphism
1)compile time
2)Run time

1)Compile:---overloading is the best example of compile-
time polymorphism.
Look at this example:----

class NewClass {

public void aSum()
{
System.out.println("hi.......");
}
// NewClass nc1=new InheritClass();
// NewClass nc=new NewClass();
}
class InheritClass extends NewClass
{
@Override
public void aSum()
{
System.out.println("over-riden......");
}
public static void main(String as[])
{
NewClass nc=new NewClass();
NewClass nc1=new InheritClass();

nc.aSum();.......compile time polymorphism
reference type determine which method to be invoke
//nc1.aSum();
}




2)Run time:Over-ridding is the example of run time
polymorphism........

look at example----
class NewClass {

public void aSum()
{
System.out.println("hi.......");
}
// NewClass nc1=new InheritClass();
// NewClass nc=new NewClass();
}
class InheritClass extends NewClass
{
@Override
public void aSum()
{
System.out.println("over-riden......");
}
public static void main(String as[])
{
NewClass nc=new NewClass();
NewClass nc1=new InheritClass();

// nc.aSum();
nc1.aSum(); //object type determine which method
shuold call
//run the example u will get idea about that
}
}
}

Is This Answer Correct ?    5 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is polymorphism and its types?

691


What polymorphism means?

703


What is overriding in oop?

649


What is persistence in oop?

749


What is Difference Between Inheritance and creating object and getting data? means Class A extends B{ B.getMethod();} (OR) Class A{ b obj=new B(); obj.getMethod(); }

2077






What does oop mean in snapchat?

790


Is this job good for future? can do this job post grduate student?

1794


What is the types of inheritance?

684


which feature are not hold visual basic of oop?

1816


What is polymorphism in oop example?

620


Why can't we have instance(stack) of a class as a member of the same class like eg.Class A{A obj;} as we can have self refential pointer

1750


Give an example where we have to specifically use C programming language and C++ programming language cannot be used?

1242


What is encapsulation and abstraction? How are they implemented in C++?

720


i got a backdoor offer in process global,Bangalore..Can i work with it?

2430


What is an example of genetic polymorphism?

753