Codementor Events

Java 101: What is the difference between final and static in Java? Is it same as const in c++ ?

Published Apr 20, 2017
Java 101: What is the difference between final and static in Java? Is it same as const in c++ ?

While taking sessions on this platform, I get several questions regarding the basic concepts of Java, one of them being the meaning of final keyword. Thought of putting it down here to help others in future.

final keyword implies something, which cannot be changed. For example - final variables cannot be reassigned, final fields in a class cannot be set once they’re defined, final methods cannot be overridden, and, final classes cannot be extended/subclassed. final in Java is more analogous to const in C++.

static keyword in Java and C++ have the same meaning. static denotes a property, which is shared by all objects/instances of a class and does not vary from one instance to another. This also means, that you do not need an instance to get access to static members, they can be accessed via the class itself.

Discover and read more posts from Rashmi
get started
post commentsBe the first to share your opinion
Show more replies