answersLogoWhite

0


Best Answer

You declare a method final in Java when you do not want any subclasses of your class to be able to override the method.

I have also heard that this allows the Java compiler to make more intelligent decisions. For example, it supposedly allows Java to decide when to make a method inline. (Note that this is all unconfirmed)

User Avatar

Wiki User

15y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

You declare a class final when you don't want any other classes to be able to extend that class.

You declare a method final when you don't want any subclasses to be able to override that method.

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

No. An abstract method must be overriden in an subclass. If the method is final then it can't be edited.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: When do you declare a method final in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

When do you declare a method or class final?

if we declare a method as final then it can be changed.


How do you prevent class extending in java?

Declare the class as final. final class A{ ... }


How do you prevent extending a class in java?

You can declare a class as "final".


How nesting of methods is done in java?

No, Java only allows a method to be defined within a class, not within another method.


When do you declare a method or class abstract in java?

when overriding of a class or a method is necessary, they can be declared as abstract


What is the return type of finally method in java?

The final and finally keywords have no impact on the return type of a method in Java.


What is out of scope in returning objects in java?

if u declare variable in method & tray to use this variable outside the method then it is out of scope


Do you use virtual functions in Java?

Every method in java that isn't a class (static) method is automatically "virtual." If you want to disable virtual overrides, make the method "final" in the base class.


What method in Java cannot be overridden?

Methods which are declared final cannot be overridden.


How many values can a method return in Java?

A method in java can declare only one return value and type at a time. For ex: a single method cannot have a code that returns a string in some cases and an integer in other cases. Java compiler does not let you do that. You can only have one return type for every method in java.


What is the relationship between inheritance methods and the keyword final?

They are inversely related. That is: If you declare a method as final you cannot overridden in the child class If you declare a class as final you cannot inherit it in any other class.


What is fix in java?

fixed method means is one which cannot be overridden by a subclass. A fixed method can be declared by prefixing the word-final before a method. We can use the keyword final to donate a constant.