classFruit{voidcutting(){System.out.print("Cutting Fruit ");}}classMangoextendsFruit{voidcutting(){super.cutting();//invokes the super class methodSystem.out.println("Mango");}}classAppleextendsFruit{voidcutting(){super.cutting();//invokes the super class methodSystem.out.println("Apple");}}classCodeaftextendsFruit{publicstaticvoidmain(Stringargs[]){Fruitm=newMango();//Mango objectm.cutting();Fruita=newApple();//Apple objecta.cutting();}}
Output
codeaft@codeaft:~$ javac Codeaft.java codeaft@codeaft:~$ java Codeaft
Cutting Fruit Mango
Cutting Fruit Apple
codeaft@codeaft:~$
Dear User, Thank you for visitng Codeaft. If you are interested in technical articles, latest technologies, and our journey further, please follow us on LinkedIn.