Method Overloadding
Methods has same name but different parameters.
bullet()
{ Action block;}
bullet(int a)
{ Action block:}
bullet(int a,int b)
{Action block;}
Method OverRiding
In inheritance, when the child class wants to redefine the parent class's method Overriding is used.
Methods have same name but redefined in the child class with same parameters.
Class P
{ public void property()
{ Sysout(Ca$h + Land + Gold);}
public void marry()
{ Sysout(Subbalaxmi);}
}
Class C extends P
{ public void marry()
{ Sysout (3sha|9Tara| Sridevi);}
}
Class P
{ public void property()
{ Sysout(Ca$h + Land + Gold);}
public void marry()
{ Sysout(Subbalaxmi);}
}
Class C extends P
{ public void marry()
{ Sysout (3sha|9Tara| Sridevi);}
}
Difference between Method OverLoading and OverRiding
Method
|
OverLoading
|
OverRiding
|
Method Name
|
must be same
|
must be same
|
Argument
Types
|
must be
different(atleast Order)
|
must be
same(including order)
|
Method
Signature
|
must be
different
|
must be same
|
Return Type
|
No
Restrictions
|
must be same
untill 1.4Version, in 1.5Version Covarient
|
Private,
Static & Final Methods
|
Can be
Overloaded
|
Cannot be
Overridden
|
Access
Modifiers
|
No
Restrictions
|
Reduce X Increase P (Cannot reduce the scope
of Access Modifier)
|
Throws Clause
|
No
Restrictions
|
of Child
->
|
Method
Resolution
|
Always tak by
Compiler based on reference type
|
Always taken
by JVM based on Runtime Object
|
Also known as
|
Complie-time
Polymorphism
|
Run Time
polymorphism
|
Static
Polymorphism
|
Dynamic
Polymorphism
|
|
Early binding
|
Late Binding
|
In OverRiding the Access Specifiers can be converted(Increased) as follows:
public
|
Øpublic
|
Default
|
Ødefault|protected|public
|
protected
|
Øprotected|public
|
private
|
Ønot applicable
|
Comments
Post a Comment