class Bank
{
double getInterestRate()
{
return 0.0;
}
}
class SBI extends Bank
{
@Override
double getInterestRate()
{
return 6.5;
}
}
class HDFC extends Bank
{
@Override
double getInterestRate()
{
return 7.0;
}
}
class ICICI extends Bank
{
@Override
double getInterestRate()
{
return 6.8;
}
}
public class Main
{
public static void main(String[] args)
{
Bank b1 = new SBI();
Bank b2 = new HDFC();
Bank b3 = new ICICI();
System.out.println("SBI Interest Rate: " + b1.getInterestRate() + "%");
System.out.println("HDFC Interest Rate: " + b2.getInterestRate() + "%");
System.out.println("ICICI Interest Rate: " + b3.getInterestRate() + "%");
}
}
SBI Interest Rate: 6.5% HDFC Interest Rate: 7.0% ICICI Interest Rate: 6.8%
// Valid override
protected void display() {}
// Invalid override (if superclass method is public)
private void display() {}
@Override
annotation is recommended to avoid mistakes and improve code readability.
@Override
void methodName() {
// implementation
}
Your feedback helps us grow! If there's anything we can fix or improve, please let us know.
Weโre here to make our tutorials better based on your thoughts and suggestions.