Page 55 - TP_iPlus_V2.1_Class8
P. 55

All the animals in the animal class have similar behaviours such as eating, drinking, and they also
                 have similar properties, such as colour, size, and number of legs.

                 In the same way, a class in Java contains different types of objects that have similar properties
                 and behaviour. After declaring a class, we can create many number of objects from it.

                  i +  FEATURES OF OOPS

                 Object-Oriented Programming (OOP) is a programming paradigm that uses objects, classes, and
                 methods to design and implement software. Some key features of OOPs are as follows:
                 •  Encapsulation: Encapsulation is the concept of bundling the data (attributes) and the methods
                    (functions) that operate on the data into a single unit, called a class. It restricts direct access
                    to some of the object’s components, which means that the internal details of how an object
                    works are hidden from the outside world. This ensures that the object controls how its data is
                    accessed and modified, promoting data integrity.

                    Example: A TV remote controls the TV by sending signals when you press buttons. However,
                    you do not need to understand how these signals are generated or how the TV processes
                    them. The internal circuitry and the way the buttons are wired are hidden from you. You only
                    interact with the remote by pressing the buttons provided.

                 •  Abstraction: Abstraction is the process of simplifying complex reality by modelling classes
                    appropriate to the problem. It focuses on exposing only the essential features and behaviours
                    of an object while hiding the internal details. The goal is to reduce complexity and allow the
                    programmer to focus on interacting with the object rather than worrying about how it works
                    internally.

                    Example: When you drive a car, you interact with the steering wheel, pedals, and gear shift.
                    You don’t need to know how the fuel injection system works, how the engine converts fuel
                    into motion, or how the braking system operates. All those details are abstracted away so that
                    you can drive the car without understanding its internal mechanics.

                 •  Inheritance: Inheritance is a mechanism where a new class (called a subclass or derived class)
                    is created from an existing class (called a superclass or base class). The new class inherits all
                    the features (attributes and methods) of the base class and can also have additional features
                    of its own. This allows for code reuse and the creation of a hierarchy of classes.

                    Example: The Vehicle is a general category for all vehicles with common features like brand,
                    model,  speed,  and  essential  functions  (starting,  stopping,  accelerating).  Specific  types  of
                    vehicles—bikes, cars, buses, and trucks—inherit these basic features from Vehicle. Each type
                    then adds its own unique attributes, such as handlebars for bikes, doors and trunks for cars,
                    large seating for buses, and cargo areas for trucks.

                                                               Vehicle





                                Bikes                 Cars                 Buses                 Trucks









                                                                                                                  53
                                                                                               Program Coding
   50   51   52   53   54   55   56   57   58   59   60