July 15 2026
What is Method Overriding?
Method Overriding is an Object-Oriented Programming (OOP) feature where a child class provides its own implementation of a method that already exists in the parent class.
Parent class
Child class
Output:
Child class (use super key)
Output:
What is the super Keyword in Java?
The super keyword is used to refer to the parent (superclass) object from a child class.
It allows a child class to access the parent class's methods, variables, and constructors.
Buy
public class Child extends ParentParent object works, but the Child value no longer runs,
-created Child object works in parent and child
Key Points
Same method name.
Same parameters.
The parent class method is redefined in the child class.
The child class method is executed when called on a child object.
Simple Errors
Variable Error
Why Does This Happen?
In Java, each local variable must have a unique name within the same method.
Here, the variable buy is declared twice.







Top comments (0)