Course Hive
Search

Welcome

Sign in or create your account

Continue with Google
or
Learn POLYMORPHISM in 6 minutes! 🎭
Play lesson

Java tutorial for beginners ☕ - Learn POLYMORPHISM in 6 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 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"); } }

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