Difference between static and non-static in java?

java dev.to

Static

  • A static member (variable or method) belongs to the class itself, not to individual objects.

  • A static method in Java is associated with the class, not with any object or instance.

  • It can be accessed by all instances of the class, but it does not rely on any specific instance.

  • Static methods can access static variables directly without the need for an object.

Non-Static (Instance)

  • An instance method belongs to an object of a class and requires an instance to be called. It can access and modify the object’s instance variables and can also call other instance or static methods.

  • Can access and modify instance variables (object state).

  • Can accept parameters and return a value.

  • Can call other instance methods or static methods.

  • Supports encapsulation and object-oriented design.

  • Follows the divide-and-conquer principle in larger applications.

Source: dev.to

arrow_back Back to Tutorials