When will you define a method as static in java?

Java

1 answer

Answer

1111126

2026-04-21 03:20

+ Follow

Static keyWord when used with a method, specifies that this method belongs to the class and not a particular instance of the class (a.k.a object of the class)

Ex:

public class StaticTest {

public static String getAuthorName() {

return "Anand";

}

}

Here getAuthorName is the static method and it can be accessed without instantiating an object of the class StaticTest. You can access this method as:

String authorName = StaticTest.getAuthorName();

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.