A class can be defined as a collection of named fields and codes organized into methods that are named according to proper syntax and operating on a particular set of data. These fields and methods that are part of a collection are termed as members of the class. Not only this, in Java, a class may contain other classes also.
The static members of the class are associated with the class itself. On the other hand, the instance members of the class are associated with separate objects or instances of the class.
The member of a class can be divided into the following categories:
- Class fields
- Class methods
- Instance fields
- Instance methods
The code snippet given below displays the class definition for the class Circle. Not that this class contains all the four members of the class Circle
public class Circle
{
// Here is an example of a field of a class
public static final double value_of_PI= 3.14159; // Note that PI has a fixed constant value used in math
// Here is an example of a method of a class which computes the value of a circle value based on the arguments