Computer Science, asked by sampurna20, 1 year ago

2 differences between static and nonstatic data members in Java​

Answers

Answered by Anonymous
1

A non-static method is always accessed using the object of class as shown in the above example.

Notes:

How to call static methods: direct or using class name:

StaticDemo.copyArg(s1, s2);

OR copyArg(s1, s2);

How to call a non-static method: using object of the class:

JavaExample obj = new JavaExample();

Important Points:

Static Methods can access static variables without any objects, however non-static methods and non-static variables can only be accessed using objects.

Static methods can be accessed directly in static and non-static methods. For example the static public static void main() method can access the other static methods directly. Also a non-static regular method can access static methods directly.


sampurna20: u differentiated between static n non static methods.. i wanted it for static n non static datamembers(variables)
Similar questions