Computer Science, asked by sirtejpal786, 4 months ago

distinguish between non static static.​

Answers

Answered by XxRedmanherexX
0

Answer:

A static method belongs to the class itself while a non-static method belongs to each instance of a class. ... Therefore, a static method can be called directly without creating any instance of the class and an object is needed to call a non-static method.

Answered by KapilChauhan1586
0

Few differences between static and non-static methods:

  • A static method belongs to the class itself while a non-static method belongs to each instance of a class. Therefore, a static method can be called directly without creating any instance of the class and an object is needed to call a non-static method.
  • We cannot access non-static member variables (aka instance member variables) from a static method without creating an instance of its class. Static methods can only access static variables while non-static methods can access both static and non-static variables.
  • Similar to non-static member variables, we cannot access any non-static method from a static method without creating an instance of its class.
  • A static method use early binding (or compile time binding) whereas a non-static method require runtime binding. This is the reason why we can call a static method without creating any instance.
  • We cannot override a static method in Java while we can override a non-static method. This is because overriding require runtime binding (Polymorphism) and static methods are bonded by compiler.
  • We cannot use this and super keywords inside a static method since they are associated to a particular instance.
  • Static methods reduces the memory footprint of the application. This is because the memory is allocated only once for static method during the time of class loading while for a non-static method, memory is allocated every time the method is called.

Mark me as Brainlist if you like the answer

Similar questions