Java Method Overriding Example


Program
class Bird{//Parent Class void fly(){ System.out.println("Bird can Fly"); } } public class Parrot extends Bird{ //Child Class void fly(){ System.out.print("Parrot can Fly "); } public static void main(String args[]){ Parrot p=new Parrot(); p.fly(); } }
Input
Output