Java Reference
In-Depth Information
In case of a person as object, corresponding states are name, color, height, age and
behaviors are eating, walking, running, etc.
Defining a class
Class is a user defined data type serving as a blueprint. A simple class is defined with the
following form:
Class classname
{
Data members or fields declaration;
// optional
Methods or member functions declaration;
// optional
}
As data members and member functions are optional, so Java allows even an empty class.
Fields and Methods declaration
As we know, data is encapsulated in Java by placing its data members and member
functions inside a class. These variables are known as instance variables as they are created
as an object is instantiated. The method of declaring instance variables is same as local
variables.
Class Person
{
Int age;
String name;
String color;
}
This class has three instance variables one age of integer type and other two name and color
of string type.
Search WWH ::




Custom Search