Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c

Method overriding in Java language

Posted on February 10, 2017January 17, 2020

Method overriding in Java language

In this tutorial, we will discuss the concept of method overriding in Java language.

We have already looked at method overloading in Java. Now, we will learn method overriding in Java. Method overriding looks like method overloading with some difference.

When a subclass has the same method as the one declared in the parent class, it is called method overriding in java.

Conditions for Java Method Overriding

  • The method must have the same signature as the base class.
  • The method must have the same parameter as the base class.
  • must be IS-A relationship with extends(inheritance)

Example

Method overriding in Java language
Syntax

Method overriding in Java language
Syntax
The diagram below explains the above two classes (School1 and School2) including their methods and their relationship.
Program 1
Method overriding in Java language
Example
Above is a single inheritance program.It contains two classes, one vehicle is the parent class and another vehicle is the child class. Class vehicles inherit the properties of the vehicle class.
Program 2

 

Method overriding in Java language
Example

Above program is a single inheritance program. It contains two classes: one vehicle is the parent class and the other vehicle is the child class. The same method is inside every class. Class vehicles inherit the properties of vehicle class.
One object is created under the main method.
When a method is called through an object, derived classes override the base class.

Program 3
 
Method overriding in Java language
Example
 

Program 4

Method overriding in Java language
Example

Explanation for the above program

Method overriding in Java language
Example

Related Post

Abstract class in C++                                           Abstract class in Java

Encapsulation in C++                                       Encapsulation in Java

Polymorphism in C++                                      Method overriding in Python

Method overloading in java                             Constructor overloading in Java

Exception Handling in Java                                    

Related

Recent Posts

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes