Course Hive
Search

Welcome

Sign in or create your account

Continue with Google
or
Learn runtime polymorphism in 5 minutes! 🤷‍♂️
Play lesson

Java tutorial for beginners ☕ - Learn runtime polymorphism in 5 minutes! 🤷‍♂️

5.0 (4)
40 learners

What you'll learn

This course includes

  • 12 hours of video
  • Certificate of completion
  • Access on mobile and TV

Summary

Keywords

Full Transcript

#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(); } } }

Course Hive

Continue this lesson in the app

Install CourseHive on Android or iOS to keep learning while you move.

Related Courses

FAQs

Course Hive
Download CourseHive
Keep learning anywhere