Page 44 - CA_Blue( J )_Class9
P. 44

In the above example, the class "student" has two attributes name (represent the student's name) and stu_type
                  (represents the type or level of the student). Here, four different objects are created:
                  •  Object 1 represents Aditi as a student of Primary level.
                  •  Object 2 represents Ananya as a student of Secondary level.
                  •  Object 3 represents Ajay as a student of Higher Secondary level.
                  •  Object 4 represents Reshma as a student of Graduate level.

                  So, we can derive from the above example that a class is a blue print or prototype and objects are the real entities
                  created based on that blueprint.

                  Let’s take another example.

                  Suppose in real world CAR is a class and the different types of cars are its instances or objects, the cars could be
                  Sedan, Hatchback, Crossover, Station wagon, Convertible, Coupe, Micro car, Electric cars etc.

                  CAR has different characteristics: Category, Speed, Model, Colour.
                  CAR has different behaviours/functions/methods : Start (), Accelerate (), Brake (), Honk ().


                                                                  Car

                                                                  Class











                    Category: Hatchback               Category: Sedan                   Category: SUV
                    Speed: 160 km/h                   Speed:  210 km/h                  Speed:  155 km/h
                                                                                        Model:  Mahindra
                    Model: Hyundai i20                Model:  Honda City                      Thar
                    Colour: Red                       Colour: White                     Colour: Black

                              Object 1                          Object 2                           Object 3


                  We can consider different types of cars owned in a house hold as different objects of class CAR. Each of the car has
                  different values for its characteristics i.e. attributes of the class CAR and the behaviour of the car are the functions
                  that a class would give to all its objects.
                  The three objects of the class have different speeds:

                  •  Object 1: Represents the Hyundai i20, with speed 160 km/h, colour Red and the Hatchback category
                  •  Object 2: Represents the Honda City, with speed 210 km/h, colour White and the Sedan category
                  •  Object 3: Represents the Mahindra Thar, with speed 155 km/h, colour Black and the SUV category

                  Thus, we find that once a class is created, many objects can be created by using the characteristics and behaviour
                  of the same class.

                  In computer programming, this concept is known as Object-Oriented Programming (OOP). In OOP, the characteristics
                  of an object are referred to as data members or instance variables. These represent the properties or attributes of
                  an object. The behaviours of an object are known as methods or member methods. These represent the actions
                  or functions that can be performed by an object.




                    42    Touchpad Computer Applications-IX
   39   40   41   42   43   44   45   46   47   48   49