Class and Object

CLASS:

CLASS is a specification of variables and methods where the variables are used for storing the data and methods are used for performing the operations. A class is a collections of objects. Class does not exit physically in the real world. A class can be considered as a user defined data type. Class is an example of Encapsultion. The following is the syntax of class:


 Class syntax
Fig: Class syntax.
A class can contain any no.of variable and any no.of methods. The variables and methods of a class together are called as members of class.

OBJECT: 


An object is anything that exists physically in the real world. Object is considered as an instance of Class. We can create any no.of objects for a class, but without class we cannot create any object. Object is used to access the members of the class, we can access both variables and methods by using object. The following is the syntax for creating an object to class.

  • Class_name  Object_name = new  Class_name( );
Syntax for accessing variable using object:
  • Object_name . Variable_name;
Syntax for accessing variable using object:
  •  Object_name . Method_name( );

No comments:

Post a Comment