07:31Learn runtime polymorphism in 5 minutes! 🤷♂️
From the creator
#java #javatutorial #javacourse import java.util.Scanner; public class Main { public static void main(String[] args) { // Runtime polymorphism = When the method that gets executed is decided // at runtime based on the actual type of the object. Scanner scanner = new Scanner(System.in); Animal animal; System.out.print("Would you like a dog or a cat? (1 = dog, 2 = cat): "); int choice = scanner.nextInt(); if(choice == 1){ animal = new Dog(); animal.speak(); } else if(choice == 2){ animal = new Cat(); animal.speak(); } } }
Published 2024-12-05 · Watch on YouTube ↗
Availability and playback restrictions are controlled by the original channel.





