Difference between method overloading and overriding in Java
Carvia Tech | August 02, 2019 | 1 min read | 266 views
For more concrete information on method overloading and overriding, you can refer to these two articles.
|Method overloading||Method overriding|
A class have two or more methods in with the same name and different argument list.
In method overriding superclass and subclass have same method signature.
In overloading return type could vary in both methods.
In overriding return types should be same class or subclass (co-variant return type).
JVM calls the respective method based on the parameters passed to it, at the time of method call. It is also known as static polymorphism.
JVM calls the respective method based on the object used to call the method. It is also known as dynamic polymorphism.
Overloaded methods can declare new or broader checked exceptions.
You shall only throw same or narrowed checked exception (same or sub-class) or none at all.
Top articles in this category:
- Java Concurrency Interview Questions and Answers
- Top 50 Multi-threading Java Interview Questions for Investment Bank
- RBS Java Programming Interview Questions
- Citibank Java developer interview questions
- Morgan Stanley Investment Banking Java Interview Questions
- Goldman Sachs Java Interview Questions for Senior Developer
- Cracking core java interviews - question bank
Find more on this topic:
Interview - Product Companies, eCommerce Companies, Investment Banking, Healthcare Industry, Service Companies and Startups.
Last updated 1 week ago
Recommended books for interview preparation:
- Spring Boot with GMAIL SMTP
- Mandrill emails in Spring Boot Java
- Top 30 Hibernate and Spring Data JPA interview questions
- Generating variable length secure key/secret in Java
- Reverse the bits of a number and check if the number is palindrome or not
- MD5 and SHA256 in Java Kotlin and Android
- Spring Security 5 - There is no PasswordEncoder mapped for the id
- Inter-thread communication in Java
- What are different thread states in Java
- Static method synchronization aka Class Lock in Java