Page 113 - 2617_JSSPS_C-7
P. 113

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






                    Polymorphism: Polymorphism allows objects of different classes  to be treated as objects of a

                   common superclass. In Object-Oriented Programming , polymorphism allows objects to be treated
                   as instances of their parent class rather than their actual class. This means that a single function or
                   method can operate on different types of objects, making the code more flexible and reusable.

                   Example: As a family car, it’s equipped with extra seats and space for luggage, making it suitable
                   for personal trips. When used as a taxi, it features a fare meter and a taxi sign for transporting
                   passengers. As a pool car for students, it includes extra safety seats and a schedule to manage
                   shared  transportation. Despite  these  different  uses, the  car remains fundamentally  the  same,
                   demonstrating how one object can fulfil multiple roles.









                                                                                               Java Programming    111
   108   109   110   111   112   113   114   115   116   117   118