Skip to the content.

Inheritance

-

What we’ll cover

Class inheritance

Object Class

Object Methods

Super and Final Keywords

-

Terminology

-

Class inheritance

-

Inheritance is an “is a” or “is like a” relationship

-

Example: SUV

public class Vehicle{
  public void start(){...}
}

class SUV extends Vehicle{
  public void drive(){
    start();
    ...
  }
}

-

Example: Corgi

class Dog{public void wag(){...}}
public class Corgi extends Dog{
  public static void main(String[] args){
    Corgi bucket = new Corgi();
    bucket.wag();
  }
}

Full example

-

Upcasting

public class App{
 public static void main(String[] args){
  Dog pembroke = new Corgi();
  pembroke.wag();
  }
}