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.
class Base
{
void showme()
{
System.out.println(" Base class method");
}
}
class Child extends Base
{
void showme()
{
System.out.println("Child class method");
}
public static void main(String... a)
{
Child obj = new Child();
obj.showme();
}
}
Output:
$ javac Child.java $ java Child Child class method
Sanfoundry Global Education & Learning Series – 1000 Java Programs.
advertisement
Here’s the list of Best Books in Java Programming, Data Structures and Algorithms.
Related Posts:
- Apply for Computer Science Internship
- Check Java Books
- Check Programming Books
- Practice Information Technology MCQs
- Practice BCA MCQs