Sobes.tech
Junior — Middle

Can you name classes declared with the final modifier in the standard JDK library?

sobes.tech AI

Answer from AI

In the standard JDK library, there are several classes declared with the final modifier. This means they cannot be inherited. Some of them:

  • java.lang.String — a class for working with strings.
  • java.lang.Integer, java.lang.Long, java.lang.Double, and other primitive type wrappers.
  • java.lang.Math — contains mathematical functions.
  • java.lang.System — provides access to system resources.
  • java.lang.ThreadLocal — provides thread-local variables.
  • java.util.Collections — utility class for working with collections.

Declaring a class as final is often used to ensure security, immutability, or optimization.

Example:

public final class String {
    // implementation
}