Hackforge Academy

Category: React • Beginner

Published on 14 Feb 2026

Explanation

#white-Method Overloading same method name but different parameters in the same class. #white-We can change Number of parameters Type of parameters Order of parameters

Code Example

class Calculator {
  int add(int a, int b) {
        return a + b;
    }
 int add(int a, int b, int c) {
        return a + b + c;
    }

double add(double a, double b){
        return a + b;
    }
}
//next slide

Explanation

Coding

Code Example

public class Main {
    public static void main(String[] args) {
        Calculator obj = new Calculator();
   System.out.println(obj.add(10, 20));            System.out.println(obj.add(10, 20, 30)); 
 System.out.println(obj.add(5.5, 2.5));
    }
}
}

Explanation

Method Overriding #white-Run-Time Polymorphism IT means child class provides its own implementation of parent class method. #white-Rules: 1.Method name must be same 2.Parameters must be same 3.Inheritance required

Code Example

class Animal {

    void sound() {
        System.out.println("Animal makes sound");
    }
}

class Dog extends Animal {

    @Override
    void sound() {
        System.out.println("Dog barks");
    }
}

Explanation

Cont..

Code Example

public class Main {
    public static void main(String[] args) {
        Animal obj = new Dog();   // Parent reference, child object
        obj.sound();              // Dog barks
    }
}

Want structured learning with real projects?

Join our Weekend Live Workshop and become job-ready faster.