STATIC KEYWORD
In a class we can have 2 types of members.
i. Instance
members – represents attributes and behavior of individual
objects.
ii.
Class members – represents attributes and behavior of the whole
class.
To understand where we need to use static, see the diagram below-
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcejUGbeC7Gf4XmEGmKE_YTgIghdBjMOagJsJSsz8T7rHrA9PDiEqdZkNWhx4b9lWwKOI1-gfQvUF2cY0w1s4-qxGa8wKt3mDUcaIIBMN8VqkQZJGw60ZGybOLhJq3-6vnNM4SW8lhUa2T/s1600/uptuexam_core_java.png)
v By default all the members of a class are instance
members. In order to associate a member of a class static keyword is
used.
v static denotes execution of whole class.
Syntax of compiling –
javac NameOfSourceFile
example -
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2Jhgr5vWJFncDwIKWlh7GGqNCA44YvPPpVxE6Z9jR6SBUFpXcQpVw7sP2UYvrFpfsS2qIlRuuQtIjC4XUeJKkA_vXeL92-ySQAV1W8AFxxyOmfXsqjnesKQGyWNwd1YaHkA1ODiSs5cU5/s1600/uptuexam_core_java.png)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9oWzKIDlwZzqLxjtyAYCR9_J85Mf2_2s00-LwVy7KB421N7KcqFQHkX7DUuGM4pf1NiDhXkbziXwIuPsTR6R-oNd7i-Pc1bDQLi47QB0TZe-N-zbTJnKC8Epg4A6UgDTjQ6LfdPtpSjp4/s1600/uptuexam_core_java.png)
No comments:
Post a Comment