Friday, June 20, 2014

Objects and Classes

OOPs (Object oriented programming) is based on two concepts: -

Objects and Classes

Objects and classes provide a better way to design the system.

Objects :-

There are three basic properties of an object-
  • State :- state represent the data  in the object. it can't change after creation.
  • Behavior :- Behavior represent the method in the objects by which the object can be used. Behavior can change.
  • Identity :- it is the property of object that distinguishes it from other objects.
For Example- electric fan (real world entity) has parts like motor, switch etc known as its state. We can change  fan behavior ON or OFF  by pressing power switch.

Classes :- 

Class is a blueprint from which an object is constructed. It is a group of objects with common attributes. Class contains-
  • members of class
  • method
Structure of Class :-

                   class <class_name>
                     {
                         members of class
                         methods
                     }

Sample of a class :-

            class Example
               {
                   String name;
                    int age;
                   void display()
                   { }

                   void hide()
                    { }
               }

No comments:

Post a Comment