A Developer Gateway To IT World...

Techie Uncle Software Testing Core Java Java Spring C Programming Operating System HTML 5 Java 8 ES6 Project

Example of Polymorphism :Method Overriding

method overriding in java

What is the polymorphism as Method overriding in Java?

Example of method overriding in java in Java:-




class Bank
{
    int getInterestRate()
    {
        return 0;
    }
}

class sbi extends Bank
{
    int getInterestRate()
    {
        return 10;
    }
}

class icici extends Bank
{
    int getInterestRate()
    {
        return 15;
    }
}

class hdfc extends Bank
{
    int getInterestRate()
    {
        return 20;
    }
}

class polymorphism1
{
    public static void main(String args[])
    {
        Bank b= new Bank();
        sbi s =new sbi();

        icici i =new icici();
        hdfc h =new hdfc();

        System.out.println(b.getInterestRate());
  System.out.println(s.getInterestRate());

        System.out.println(i.getInterestRate());
        System.out.println(h.getInterestRate());
    }
}



 

LEARN TUTORIALS

.

.