Java: Final method

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

As was mentioned in the previous post, we can define a method as a final method so that it can not be overriden in the subclasses.

package overridetest;

class Music {

    int i = 1;

    final int fan() {
        return i;

    static String groupie() {
        return "Music";

class Rock extends Music {

    int i = 2;

    static String groupie() {
        return "Rock";

public class OverrideTest {

    public static void main(String args[]) {
        Rock r = new Rock();



If you define a class as a final class, you will not be able to extend it.  Extending a final class will create a compile time error.

Series Navigation<< Java: The final keyword
Java Example: Reversing a string using StringBuilder Class >>

Leave a comment

Leave a Reply