Java program for Hybrid Inheritance (Multilevel and Hierarchical)
KW.java
class Bank
{
    void Bonus()
    {
        System.out.print("Festival Bonus: ");
    }  
}
class WhiteBank extends Bank
{
    void WhiteBankBonus()
    {
        super.Bonus();
        System.out.println("WhiteBank 1500");
    }
}
class GreenBank extends WhiteBank
{
    void GreenBankBonus()
    {
        super.Bonus();
        System.out.println("GreenBank 500");
    }
}
class PinkBank extends WhiteBank
{
    void PinkBankBonus()
    {
        super.Bonus();
        System.out.println("PinkBank 1000");
    }
}

class KW 
{
    public static void main(String[] args) 
    {
        GreenBank gb=new GreenBank();
        gb.GreenBankBonus();
        gb.WhiteBankBonus();
        
        PinkBank pb=new PinkBank();
        pb.PinkBankBonus();
        pb.WhiteBankBonus();
    }
}
Output
kodingwindow@kw:~$ javac KW.java
kodingwindow@kw:~$ java KW Festival Bonus: GreenBank 500 Festival Bonus: WhiteBank 1500 Festival Bonus: PinkBank 1000 Festival Bonus: WhiteBank 1500 kodingwindow@kw:~$
What Next?
Java Polymorphism
Advertisement