Thursday 26 February 2015

Classes in Java

       A class is the logical construct upon which entire java language is built. The class defines the shape and nature of an object. it consists of variables and methods.

      A class defines a new data type . An objects is the instance of the class and the objects can be created of the type class. In simple we can say class is template of the object and object is instance of the class.

General Syntax:


       The class can have only 2 access specifier i.e default and public. If you declare a class without any access specifier then it will consider it as default . If you wish to declare a class as public then you have to specify like
public class_name{//Body of the class}

Creating Object:
You can create an object of a class using below syntax
class_name object_name=new class_name();
you can call a method using (.) operator i.e object_name.method_name(parameter_list);

Example:


Output:








No comments: