Junior — Middle
What static methods in Java are available without the need to create an instance of the class?
sobes.tech AI
Answer from AI
In Java, static methods belong to the class rather than an instance, so they can be called without creating an object. Examples of such methods:
- Methods from the
Mathclass, for example,Math.sqrt(),Math.abs(). - Methods from the
Collectionsclass, for example,Collections.sort(). - Methods from the
Arraysclass, for example,Arrays.asList(). - Methods from the
Integerclass, for example,Integer.parseInt().
Example of calling a static method without creating an object:
int number = Integer.parseInt("123");
double root = Math.sqrt(16);
In Android, static utility methods are also frequently used, for example, TextUtils.isEmpty() or Log.d().