Polymorphism :
Polymorphism is the ability of an object to take on many forms.The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a child class object (inheritance).
Polymorphism in java is a concept by which we can perform a single action by different ways. Polymorphism is derived from 2 greek words: poly and morphs. The word "poly" means many and "morphs" means forms. So polymorphism means many forms.
There are two types of polymorphism in java: compile time polymorphism (overloading) and runtime polymorphism (overriding). We can perform polymorphism in java by method overloading and method overriding.
public class Animal{} public class Deer extends Animal {}
Overloading Method :
Overloading is determined at the compile time. It occurs when several methods have same names with:a. Different method signature and different number or type of parameters.
b.Same method signature but different number of parameters.
c.Same method signature and same number of parameters but of different type
Overriding Method :
Overriding occurs when a class method has the same name and signature as a method in parent class. When you override methods, JVM determines the proper methods to call at the program’s run time, not at the compile time.
No comments:
Post a Comment