Core Java Tutorials


Java Hello World

Java Compilation

JDK New Features

JVM Architecture

Java OOPs Concepts

Java Package


Exception Handling


Immutable Class

File Handling




Concurrent Package


Collection Internal



Reflection In Java


Class Loader

Java Inner classes

Garbage Collector


References In Java

Heap Dump & Thread Dump

Method Overriding in Java

Method overriding in Java is a features of OOPS concept which allows programmer to create two methods with same method signature on interface and its various implementation and actual method is called at runtime depending upon type of object passed at runtime. in other words, using Method overriding we can modify the existing behavior of a class as per our need using inheritance.

In Inheritance the class which define the command functionality is known as base class or super class and class which inherits the functionalities and attributes of base class is known as derived class or sub class.

Inheritance allows reusability of the code and inheritance is one of the feature of Object-Oriented Programming (OOPs).

Rules for method overriding:

Signature of method added into subclass should be same as super class method.
The access level in subclass method cannot be more restrictive than the overridden method's define in super class.
An overriding method can throw any uncheck exceptions, regardless of whether the overridden method throws exceptions or not. However the overriding method should not throw checked exceptions that are new or broader than the ones declared by the overridden method. The overriding method can throw narrower or fewer exceptions than the overridden method.

Important points about method overriding:

Method overriding is implemented across two different classes with inheritance not within the same class.
A final method cannot be overridden.
A static method cannot be overridden but it can be re-declared.
Only inherited method can be overridden.
Constructors cannot be overridden since Constructors is not inherited.

Example of method overriding