Java Program to Display Method Overriding in a Class using Inheritance Class

This is a Java Program to Show Method Overriding in a Class Using Inheritance Class.

In a class hierarchy, when a method in a subclass has the same name and type signature as a method in its superclass, then the method in the subclass is said to override the method in the superclass. Here we made showme() method in both classes and achieve the concept of Method Overriding.

Here is the source code of the Java Program to Show Method Overriding in a Class Using Inheritance Class. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.

  1. class Base
  2. {
  3.     void showme()
  4.     {
  5.         System.out.println(" Base class method");
  6.     }
  7. }
  8.  class Child extends Base
  9. {
  10.     void showme()
  11.     {
  12.       System.out.println("Child class method");
  13.     }
  14.     public static void main(String... a)
  15.     {
  16.        Child obj = new Child();
  17.        obj.showme();
  18.     }
  19. }

Output:

$ javac Child.java
$ java Child
 
Child class method

Sanfoundry Global Education & Learning Series – 1000 Java Programs.

advertisement
advertisement

Here’s the list of Best Books in Java Programming, Data Structures and Algorithms.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.