Simple Class

class Body
{
public long idNum;
public String name;
public Body orbits;

public static long nextID = 0;
}

A class is declared using the keyword class, giving the class a name and listing the class members between curly braces. A class declaration creates a type name, so references to objects of that type can be declared with a simple

Body mercury;
This declaration states that mercury is a variable that can hold a reference to an object of type Body. The declaration does not create an objectit declares only a reference that is allowed to refer to a Body object. During its existence, the reference mercury may refer to any number of Body objects. These objects must be explicitly created. In this respect, the Java programming language is different from languages in which objects are created when you declare variables.

Class Members

A class can have three kinds of members:

  • Fields are the data variables associated with a class and its objects and hold the state of the class or object.

  • Methods contain the executable code of a class and define the behavior of objects.

  • Nested classes and nested interfaces are declarations of classes or interfaces that occur nested within the declaration of another class or interface.


We Are Founder..