Inheritance:

Abstract classes

Video Tutorial

What is an Abstract Class?

Defining Abstract Classes

Abstract Methods

Final Classes

What is an Abstract Class?

How does it affect its children classes?

Deciding on Declaring a class Abstract

Defining Abstract Classes

abstract public class Shape {
  private double width;
  private double height;
  public Shape(double width, double height) {
    this.width = width;
    this.height = height;
  }
  // getters & setters omitted
}

Deciding on declaring a method Abstract

Declaring Abstract Method

abstract public class Shape {
  abstract public Double getArea();
}

Declaring Abstract Method

public interface Shape {
  Double getArea();
}

Providing implementation for Abstract Method

public class Square extends Shape {
  public Square(double length) {
    super(length, length)
  }

  @Override
  public Double getArea() {
    return Math.pow(length, 2);
  }
}

Declaring a Final Class

Declaring a Final Class Examples

public final class Square extends Shape {
  public Square(double length) {
    super(length, length)
  }
  public Double getArea() {
    return Math.pow(length, 2);
  }
}

Final Methods