
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
Can we change method signature in overriding in Java?
No, while overriding a method of the super class we need to make sure that both methods have same name, same parameters and, same return type else they both will be treated as different methods.
In short, if we change the signature, you cannot override the super class’s method if you try the method of the super class will be executed.
Reason − If you change the signature both are considered as different methods and, since the copy of super class method is available at sub class object, it will be executed.
Example
class Super { void sample(int a, int b) { System.out.println("Method of the Super class"); } } public class MethodOverriding extends Super { void sample(int a, float b) { System.out.println("Method of the Sub class"); } public static void main(String args[]) { MethodOverriding obj = new MethodOverriding(); obj.sample(20, 20); } }
Output
Method of the Super class
- Related Articles
- Can we change an exception of a method with throws clause from unchecked to checked while overriding it in java?
- Method overriding in Java
- Can we change return type of main() method in java?
- Java Signature getAlgorithm() method
- Java Signature getProvider() method
- Java Signature toString() method
- Java Signature getInstance() method
- overriding method different package in java
- When Method Overriding occurs in Java?
- What is a method signature in Java?
- method overriding with access modifiers in Java
- Exception handling with method overriding in Java.
- Difference between Method Overloading and Method Overriding in Java
- Rules for Java method overriding
- Java Signature getAlgorithm() method with Examples

Advertisements