What is Method Overriding - Method Overriding in Java, What is Runtime Polymorphism in Java


What is Method Overriding - Method Overriding in Java, What is Runtime Polymorphism in Java

Method Overriding is a technique to override a existing task from a method and assign a new task to that method. or one or more method with same name and same signature into two or more classes and every method gives its own definition.The method overriding only be achieve by the help of inheritance and two or more classes.
The Method Overriding sometimes called Runtime Polymorphism.


Example 


interface DrawShape

public void draw();
}

class Circle implements DrawShape
{
public void draw()
{
System.out.println("You are in Circle class");
}


class Triangle
{
public void draw()
{
System.out.println("You are in Triangle class");
}
}

In above example i made an interface with draw() method and then implements that method into two classes and each class define draw() method according to its requirement.

{ 0 comments... read them below or add one }

Post a Comment