Java: The final keyword

This entry is part 52 of 54 in the series Learn Java

The final keyword in Java is very similar to const in C++.  It can be used to apply to variable, method or a class in Java.

If it is applied to variable, it means the variable could not later be changed.

If it is applied to method, it means the method cannot not be overriden by subclasses.

If it is applied to object, it means the methods in the object is final.

In the example below, we apply the final keyword to a variable.

package music;

public class Music {

    public static class Play {

        final int count = 10;

        void play() {


    public static void main(String[] args) {

        Play p = new Play();;


Series Navigation<< Java: @Override
Java: Final method >>