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.
Home 
  Java Book 
    Class  

Class Creation:
  1. Introducing Classes
  2. A Simple Class
  3. A Closer Look at new
  4. Variables and Initialization
  5. this Keyword
  6. A Demo Class
  7. The Person class: another demo
  8. Understanding static