group-icon
Java Developers
Group for Java developers and programmers. Ask questions and get answers related to Java programming
254 Members
Join this group to post and comment.
Archana Priyadarshini
Archana Priyadarshini
Computer Science
03 Feb 2019

Restrictions on static methods

A static method belongs to the class rather than the object.

  1. The static method can not use non-static data member or call the non-static method directly.
  2. this and super cannot be used in static context as they are non-static.

AdhikariHarika Reshma
AdhikariHarika Reshma
Computer Science
1mo ago

Because a static method is invoked without a class instance we cannot use this or super reference in static method.It is illegal to reference any of the class fields or methods using a reference within a static method.

1.The static method cannot use non static data member or call non static method directly.

2.This and super keywords cannot be used in static context.

3.Access only static type data(static type instance variable).

4.Call only static method if non static then compile time error.

5.No need of the class object to call the static method.

6.Cannot use this and super keywords otherwise compile time error

Shruthi Pillai
Shruthi Pillai
Information Technology
1mo ago

The static keyword in Java is used for memory management 

The static can be:

  1. Variable 
  2. Method 
  3. Block
  4. Nested class

A static method belongs to the class rather than the object of a class.A static method can be invoked without the need for creating an instance of a class. A static method can access static data member and can change the value of it.

There are two main restrictions for the static method. They are:

  1. The static method can not use non static data member or call non-static method directly.
  2. this and super cannot be used in static