Utilizor
Contact Us

Java Modifiers

Access levels and other properties.

Examples

Final Class

Prevents inheritance.

final class Vehicle {
  // ...
}

// class Car extends Vehicle { ... } // Error: cannot inherit from final class

Abstract Method

Abstract method must be implemented by subclass.

abstract class Main {
  public String fname = "John";
  public int age = 24;
  public abstract void study(); // abstract method
}

// Subclass (inherit from Main)
class Student extends Main {
  public int graduationYear = 2018;
  public void study() {
    System.out.println("Studying all day long");
  }
}

Test Your Knowledge

Java Quiz

No quiz available for this topic yet.