0 votes
1 view
in Java by (4.9k points)
Can anyone tell me the restrictions applied to Java static methods?

1 Answer

0 votes
by (11.1k 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 Java training course.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...