Category Archives: Declaration

How to declare Methods, fields and classes.

Fields Declaration :

We can Declare the instance variable exactly the same way as we declare local variables.

class Rectangle
{
int length;
int height;
}

Note: These variables are only declared and therefore no storage space has been created in the memory.Instance variables are also known as member variables.

Defining a class :

A class is a user defined data type with a template that serves to define its properties.It is a blueprint from which individual objects are created.In java variables are termed as Instances of classes, which are the actual Objects.

The basic form of a class definition is :

class classname [extends superclassname ]
{
[ fields declaration; ]
[ methods declaration; ]
}

The keyword extends indicates that the properties of  superclassname class are extended to the classname class.
Fields and methods are declared inside the body.