Final, Finally (Part 2: Final Class)

welcome to part 2 of Final Keyword. Lets Start …

Final Class

We can declare a class as final. After that we cant create child class under that final class.

example time.

public final class King {
    public static void main (String args []){
        System.out.println("king Arthur");   

public class Test extends King {

// compile error: cannot inherit from final King

so why on earth you want a final class,

1. Final classes (Immutable) are read-only.
2. Thread safe, no synchronization overhead.

a very good explanation

Enjoy 🙂


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s