Skip to content

PRO TIP Block youtube.com at the DNS level โ€” Pi-hole, NextDNS or your hosts file โ€” but allow youtube-nocookie.com and i.ytimg.com. These tutorials keep playing; the rabbit hole does not.

Learning without distractions

Learn POLYMORPHISM in 6 minutes! ๐ŸŽญ

36.5K views on YouTube

#java #javatutorial #javacourse

public class Main {
public static void main(String[] args) {

// Polymorphism = “POLY-” = “MANY”
// “-MORPH” = “SHAPE”
// Objects can identify as other objects.
// Objects can be treated as objects of a common superclass.

Car car = new Car();
Bike bike = new Bike();
Boat boat = new Boat();

Vehicle[] vehicles = {car, bike, boat};

for(Vehicle vehicle : vehicles){
vehicle.go();
}
}
}
public abstract class Vehicle {

abstract void go();
}
public class Car extends Vehicle{

@Override
void go(){
System.out.println(“You drive the car”);
}
}
public class Bike extends Vehicle{

@Override
void go(){
System.out.println(“You ride the bike”);
}
}
public class Boat extends Vehicle{

@Override
void go(){
System.out.println(“You sail the boat”);
}
}