Mega Code Archive

 
Categories / Java Book / 002 Class
 

0135 Introducing Classes

A class defines a new data type. A class is a template for an object, and an object is an instance of a class. Class has data and the code that operates on that data. A class is declared by use of the class keyword. The general form of a class definition is shown here: class classname { type instance-variable1; type instance-variable2; // ... type instance-variableN; type methodname1(parameter-list) { // body of method } type methodname2(parameter-list) { // body of method } // ... type methodnameN(parameter-list) { // body of method } } The data defined within a class are called instance variables. Each object of the class contains its own copy of the instance variables. The methods and variables defined within a class are called members of the class.