Friday, June 21, 2013

Java Classes and Interfaces

Class declaration

<modifier> class <classname> extends
    <superclass> implements <interface>
{

   // Constructor
   public <classname>(<datatype> someArg)
  {
  }
   // Another constructor
   public <classname>()
  {
    // call the other constructor
    this(someValue);
  }
   // member declarations
  <access specifier> <static/final/transient/volatile> <datatype> <variablename>;

   // method declarations
  <access specifier> <static/final> <return type> <method name> <argument list>
  {
     // method body
  }
}

Interface declaration

interface <interface name>
{
   <return type> <method name> <argument list>;  // no body for the method
}