General Form of a Class
So a “class”
in java is a fundamental building block of a program or in simple words I can
say that it is a name given to the program.
There may
exist a question that “Why would one give a name to a program using “class”
while the purpose of the program is to get execute and just run on a machine”.
The above statement could be true in some cases; for example consider in C
Language we will not mention any class name there, all we do is to write and
run the code.
But remember
that C is a structure-Oriented language and Java is a Object-Oriented Language.
So, by naming the class in java you are able to implement the features of OOP
like Abstraction, Encapsulation and Data hiding.
You will see
how we use class names to implement these OOP principles mentioned above in
further posts.
For now consider the below picture which depicts the generalized form of class
The instance-variables are the member fields of the class. They show the characteristics of the class.For now consider the below picture which depicts the generalized form of class
The methods could be declared inside the class and could be accessed within the class. If any other class wants to access these members then that particular class should create an object of the class whose members it needs to access.
The Object creation will be discussed in the next post.
Bye! Keep visiting

No comments:
Post a Comment