Welcome to Questionaries, where you can ask questions and receive answers from other members of the community.

Let us know at info@questionaries.org

What does it mean that a class or member is final in java?

6 like 0 dislike
Hello
What does it mean that a class or member is final in java?
please reply me. i am waiting for your reply.
Thanx
asked 1 year ago by DBA-boss (120,990 points)

1 Answer

2 like 0 dislike
 
Best answer
A final class can no longer be subclassed. Mostly this is done for security reasons with basic classes like String and Integer. It also allows the compiler to make some optimizations, and makes thread safety a little easier to achieve. Methods may be declared final as well. This means they may not be overridden in a subclass.
Fields can be declared final, too. However, this has a completely different meaning. A final field cannot be changed after it's initialized, and it must include an initializer statement where it's declared. For example,
public final double c = 2.998;
It's also possible to make a static field final to get the effect of C++'s const statement or some uses of C's #define, e.g. public static final double c = 2.998;
answered 1 year ago by eagles11 (179,830 points)

Related questions

5 like 0 dislike
1 answer
5 like 0 dislike
1 answer
2 like 0 dislike
1 answer
2 like 0 dislike
1 answer
5 like 0 dislike
1 answer