Java Program using method overriding


In this program, You will learn how to implement method overriding in Java.


class First { void msg(){} }

class Test extends First { void msg(){} }


Example: How to implement method overriding in Java

Run it Now
class First {

    void msg() {
        System.out.println("Parent method is called here");
    }
}

class Main extends First {

    void msg() {
        System.out.println("Child method is called here");
    }

    public static void main(String args[]) {
        Main t = new Main();
        t.msg();
    }
}

Output:

Child method is called here