.

Java Tutorial: Overriding in Java

Overriding

It is actually a method overriding.

When the super classNameand sub classNamehas the identical function prototype, then it is termed as overriding of method

When a method is represented with a keyword final, it is impossible to override

Its Advantages are

Supports Identical Function Prototype in both super and sub classes

The subclassNamecan employ its super classNamefunctionality

Syntax

{`
classNameold_class
{
public void funcn1(void)
{}
}
classNamenew_classNameextends old_class
{
public void funcn1(void)
{}
}
`}

Rules to be adhered are

  • Arguments and return_type given in overridden methods are to be alike
  • Access specifier is to be same and non restricted like public or protected
  • Private, final and static methods are invalid
  • Constructors is invalid
  • Method of instance is allowed only by an inheritance

Example

overriding img1

The underlying example shows how a super keyword is employed to override the super classNamefunction

overriding img2
.