answersLogoWhite

0

The keyword "final" means that the data will not be able to be edited at a later time. The code:

final int accounts = 10;

would make the integer "accounts" equal to ten and would return an error if you were to later do something like:

accounts = 5;

This is useful if you want to make sure that you don't accidentally change data.

User Avatar

Wiki User

14y ago

What else can I help you with?

Related Questions

Discuss final method and final classes?

a method declared final can not be overridden, and a class declared as final can not be extended by its sub class.


When do you declare a method or class final?

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


Can you override an instance method and make it final?

No. Once a method is declared final in a class, no derivative of that class can override that method.


Can you have a final abstract class?

No. The abstract keyword means that you cannot instantiate the class unless you extend it with a subclass. The final keyword means that you cannot create subclasses of that class.Combining them would lead to an unusable class, so the compiler will not let this happen.


How can you create a class which cannot be inheritable?

Declare it final.


How to create immutable class in java?

by making that class final


How do you prevent method overriding in java?

Use the word "final" directly preceding your method declaration. The presence of final keyword directs java to ensure that, this particular method would not be overridden by any of its child classes.


Can be create a method within a method in java?

I don't believe it is possible, and anyways there really isn't any reason to do that. Just create a new method in the same class, or in a "utility" class


Why final method are used in java?

Final methods are used when a class is inheritable but should have some functions that must not be overridden for them to operate properly. This allows a class that can be inherited, but still have limits on its customization. Usually, final methods are declared so that a method that accepts a parameter of class A can accept a parameter of class B that inherits from A, and the designer of class A can still be certain that the method will operate as intended regardless of what the developer does in class B.


When do you declare a method final in java?

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)


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 the final keyword in Java?

The final keyword precedes a declared constant which after Instantiation cannot be modified. Examples. final double PI = 3.14; PI = 1234; // does not compile //or final double ONE; ONE = 1; // Instantiated ONE = 2; // does not compile ---------------------------------------- final keyword can also apply to a method or a class. When applied to a method - it means the method cannot be over-ridden. Specially useful when a method assigns a state that should not be changed in the classes that inherit it, and should use it as it is (not change the method behaviour). When applied to a class it means that the class cannot be instantiated. A common use is for a class that only allows static methods as entry points or static final constants - to be accessed without a class instance. A good example is Java's: public final class Math extends Object