Java Final Class Example

 

We cannot extend final class in java. This means if class FinalClass is final, we cannot use extends FinalClass in any other class.

This is example of Java final class

 

FinalClass.java


public final class FinalClass {

}

Cannot Extended

SubClass.java


public class SubClass extends FinalClass{

	public static void main(String[] args) {

	}
}

Compiler will throw error at extends FinalClass The type SubClass cannot subclass the final class FinalClass

Tags:

 

Leave a Reply