Polymorphism

Polymorphism is a core concept of Object Oriented Programming (OOP). It allows objects to behave differently based on their specific class. Polymorphism is usually achieved via Method Overloading or Method Overriding.

Example of Polymorphism (in Java)

// Base class: Person
class Person {
	void printRole() {
		System.out.println("I am a person.");
	}
}
 
// Derived class, student, overrides the role method (and adds new method)
class Student extends Person {
	@Override
	void printRole() {
		System.out.println("I am a student");	
	}
	
	void study() {
		System.out.println("Studying...");	
	}
}