Java_Methods_Overloading_Overriding
Java_Methods_Overloading_Overriding
1. Methods in Java
A method is a block of code that performs a specific task. It is executed when called.
Syntax:
returnType methodName(parameters) {
// code
2. Method Overloading
Definition: Method Overloading means having multiple methods in the same class with the same name but
Key Points:
- Return type can be same or different, but doesn't matter for overloading.
Example:
class Calculator {
return a + b;
return a + b;
return a + b + c;
Java Methods, Method Overloading, and Method Overriding
3. Method Overriding
Definition: Method Overriding means redefining a method in a subclass that already exists in the superclass.
Key Points:
Example:
class Animal {
void sound() {
@Override
void sound() {
System.out.println("Dog barks");