- A static method can access only static fields.
- A static method cannot access non-static fields.
- A static method cannot be called using object of a class.
- A static method can be called using Class name.
- Static fields can be used using Class Name.

A static method cannot access non-static fields

Error Message

A static method cannot be called using an object of a class
Usually intellisense gives the list of method names available for a particular object. But here intellisense cannot show any user defined method.

A static method can be accessed using Class Name
Here Intellisense has the respective method name of the particular class.

Output

Static fields can be accessed using Class Name

Output

No comments:
Post a Comment