Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (6.5k points)
Can anyone tell me the restrictions applied to Java static methods?

1 Answer

0 votes
by (11.3k points)
edited by

The biggest restriction is that a static function CANNOT call a non-static data member or function without creating an instance to achieve that. This is why, in main functions, we create objects of classes to use any non-static data member.

Secondly, keywords such as 'this' and 'super' can't be used in the static context and are only relevant when multiple instances of a class exist. This means that even if you create objects of a class and try to use the aforementioned keywords since we are not actually instantiating the data members, an error will be thrown.

If you want to master Java, visit this online Java Course.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...