Class in Java

Class is  a prototype of used to define the variables and methods common to all objects of certain kind.

A typical class definition consists of:

  • Class declaration
  • Class body
  • Variables / Attributes (static / non-static)
  • Methods (static / non-static)
  • Constructors
  • Finalize method (if cleaning up is necessary)
Class Example
In the above Example
  • Car : Class
  • Price, Model, isTankEmpty : Class  Variables/Member Variables
  • drive(), getPetrol() : Member Method