Makc
Makc

Reputation: 109

When i have to use java final method?

I understand that a final method cannot be overridden. But when i need to use it in practice? Can smbd say me simple rule when i have to use it.

class A 
{
    final void m1() 
    {
        System.out.println("This is a final method.");
    }
}

Upvotes: 0

Views: 66

Answers (1)

TheEntropyShard
TheEntropyShard

Reputation: 68

If you are coding smth for yourself, or a GUI application, for example, you'll probably never need to make your methods final. But, if you are making a library, and making some core functionality that you don't want to be changed by other programmers who will use it, you can use final keyword.

Upvotes: 1

Related Questions