Learn Java Tutorial for Beginners (Video), Part 26: Polymorphism

This is a tutorial on polymorphism; a big word for a fairly simple but very useful concept, without which object-oriented programming would be a lot trickier.

When the video is running, click the maximize button in the lower-right-hand corner to make it full screen.

Code for this tutorial:



public class App {

    public static void main(String[] args) {
        Plant plant1 = new Plant();
        // Tree is a kind of Plant (it extends Plant)
        Tree tree = new Tree();
        // Polymorphism guarantees that we can use a child class
        // wherever a parent class is expected.
        Plant plant2 = tree;
        // plant2 references a Tree, so the Tree grow() method is called.
        // The type of the reference decided what methods you can actually call;
        // we need a Tree-type reference to call tree-specific methods.
        // ... so this won't work.
        // Another example of polymorphism.
    public static void doGrow(Plant plant) {





public class Plant {
    public void grow() {
        System.out.println("Plant growing");




public class Tree extends Plant {

    public void grow() {
        System.out.println("Tree growing");
    public void shedLeaves() {
        System.out.println("Leaves shedding.");