Today I learned about Method Overriding, which is part of Runtime Polymorphism in Java.
Method Overriding happens when a child class provides its own implementation of a method that is already defined in the parent class.
β Same method name
β Same parameters
β Different implementation in child class
π» Example
Parent Class β RbiBank
package overriding;
public class RbiBank {
void interestRate() {
System.out.println("5% interest for fixed deposit upto 1 Lakh");
}
}
Child Class β SbiBank
package overriding;
public class SbiBank extends RbiBank {
@Override
void interestRate() {
System.out.println("10% interest for fixed deposit upto 1 Lakh");
}
public static void main(String[] args) {
SbiBank sbi = new SbiBank();
sbi.interestRate();
}
}
π Output
10% interest for fixed deposit upto 1 Lakh
Here the SbiBank class overrides the method of RbiBank, so the child class implementation executes.
π Relationship
RbiBank (Parent Class)
β
SbiBank (Child Class)
This demonstrates Inheritance + Method Overriding.
π― Key Points Learned
β Child class overrides parent method
β Used for Runtime Polymorphism
β Method name and parameters must be same
β @override annotation improves readability
β Helps build flexible and reusable code
π What Iβll Learn Tomorrow
π Encapsulation
Topic:
Data Protection
Private variables
Getter & Setter methods
π¨βπ« Trainer: Nantha from Payilagam
π€ A Small Note
I used ChatGPT to help structure and refine this blog while ensuring the concepts remain aligned with my trainerβs explanations.

Top comments (0)