class Calculator
{
void add(int a, int b)
{
System.out.println(a+b);
}
void add(double a, double b)
{
System.out.println(a+b);
}
}
Calculator calc = new Calculator(); // Reference type = Calculator
calc.add(5, 10); // method signature = add(int, int) β decided at compile-time
class Animal
{
void makeSound()
{
System.out.println("Some generic sound");
}
}
class Dog extends Animal
{
void makeSound()
{
System.out.println("Dog barks");
}
}
Animal obj = new Dog(); // Reference type = Animal, Object type = Dog
obj.makeSound(); // Method decided at runtime β calls Dog's makeSound()
Animal myDog = new Dog();
Your feedback helps us grow! If there's anything we can fix or improve, please let us know.
Weβre here to make our tutorials better based on your thoughts and suggestions.