In this Java article, you will learn how to use final keyword in Java with code example.
In Java, the final keyword can be applied to declaration of classes, methods and variables.
        final class A { }
        then the following code will not compile:        class B extends A {} // compile error
                class C {
            final void foo() { }
        }
        the subclass D attempts to override the method foo(), but fail because foo() is marked as final:        class D extends C {
            void foo() { } // compile error
        }
                final String message = "HELLO";
        Once the variable message is initialized and marked as final, the following code attempts to assign another value to it, will fails:        message = "BONJOUR";    // compile error
        Note: a class cannot be both abstract and final.
See all keywords in Java.
 Nam Ha Minh is certified Java programmer (SCJP and SCWCD). He began programming with Java back in the days of Java 1.4 and has been passionate about it ever since. You can connect with him on Facebook and watch his Java videos on YouTube.
Nam Ha Minh is certified Java programmer (SCJP and SCWCD). He began programming with Java back in the days of Java 1.4 and has been passionate about it ever since. You can connect with him on Facebook and watch his Java videos on YouTube.