Search This Blog

If you like any posts in this blog then click this icon which is present under the post

Wednesday 12 October 2011

Defining a Class


                A class is a user defined data type. It contains data and its related methods. The general form is

class classname
{
     Datatype field-1;
      ……………………….
     Datatype field-n;
     Datatype methodname-1(parameter list)
     {
           Body of the method
      }
     ………………………..
     Datatype methodname-n(parameter list)
     {
          Body of the method
     }
}


Where
                class                       -              keyword
                classname           -              user defined name
                datatype              -              available data types such as int,long etc.
Rules
1. The fields and methods defined inside a class are called instance variable and instance methods.
2. The fields and methods declared within a class are called members of a class.
3. The fields and methods definition are all optional.
4. The class can be empty.
5. It is better to write the first letter of the class name in capital letter.

No comments:

Post a Comment

Followers