Learn runtime polymorphism in 5 minutes! πŸ€·β€β™‚οΈ @BroCodez
Learn runtime polymorphism in 5 minutes! πŸ€·β€β™‚οΈ  @BroCodez
Uploaded December 2024 | Updated September 2026, 1 week ago
#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();
}
}
}
Learn runtime polymorphism in 5 minutes! πŸ€·β€β™‚οΈAdd CSS to Python in 10 minutes! 🎨Lets code a BANK PROGRAM with C programming! πŸ’΅Convert decimal to hexadecimal EASY!Learn Python generator expressions in 9 minutes! ♻️Learn CONSTRUCTORS in 10 minutes! πŸ”¨Learn Java while loops in 12 minutes! ♾️MongoDB indexes explainedArrays of structs are easy! πŸ—„οΈGenerate random numbers in C! 🎲Learn hexadecimal in 0x7A secondsLets code a HANGMAN GAME in Python! πŸ•Ί
Bro Code |

Learn runtime polymorphism in 5 minutes! πŸ€·β€β™‚οΈ

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER