0% found this document useful (0 votes)
12 views

Method Overriding: Superclass, Then The Method in The Subclass Is Said To Override The Method in The Superclass. When An

Method overriding occurs when a subclass defines a method with the same name and signature as a method in its superclass, replacing the superclass version with its own. When overridden methods are called from the subclass, the subclass version is always executed instead of the superclass version. Method overriding allows subclasses to define specialized behavior for existing methods while reusing attributes and behaviors from the parent class.

Uploaded by

Ammu Mole
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Method Overriding: Superclass, Then The Method in The Subclass Is Said To Override The Method in The Superclass. When An

Method overriding occurs when a subclass defines a method with the same name and signature as a method in its superclass, replacing the superclass version with its own. When overridden methods are called from the subclass, the subclass version is always executed instead of the superclass version. Method overriding allows subclasses to define specialized behavior for existing methods while reusing attributes and behaviors from the parent class.

Uploaded by

Ammu Mole
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Method Overriding

In a class hierarchy, when a method in a subclass has the same name and type signature as a method in its
superclass, then the method in the subclass is said to override the method in the superclass. When an
overridden method is called from within a subclass, it will always refer to the version of that method defined
by the subclass. The version of the method defined by the superclass will be hidden.
In other words, If subclass provides the specific implementation of the method that has been provided by one
of its parent class, it is known as method overriding.
Usage of Java Method Overriding
Method overriding is used to provide specific implementation of a method that is already provided by its
super class.
Method overriding is used for runtime polymorphism

Rules for Java Method Overriding


1. method must have same name as in the parent class
2. method must have same parameter as in the parent class.

You might also like