Page 66 - Viva ICSE Computer Studies 8 : E-book
P. 66

Class

                    A class is a collection of similar objects. For example, fruits is a class.

                    A class is a blueprint of an object. It defi nes the data and function column to a particular object.
                    So, let’s say you want to use a person in your program. You want to describe the person and
                    have the person do something. A class called ‘person’ would provide a blueprint for what a
                    person looks like and what a person can do. To actually use a person in your program, you
                    need to create an object. You use the person class to create an object of the type ‘person.’
                    A class consist of two aspects: variables and functions. A variable forms the state of an object
                    and a function uses these variables to perform various operations. Once a class is defi ned,
                    we can create many objects belonging to that same class but all the objects should share a
                    common state and behavior. All objects belonging to a particular class are called instances of
                    that class.


                    Features of Object–Oriented Programming

                    Object-oriented programming (OOP) is the latest approach in programming. It attempts to
                    eliminate most of the drawbacks of procedure-oriented programming by incorporating new
                    concepts. It is a new way of organising programs which is not dependent upon any particular
                    language. Let’s look at some of the features of object-oriented programming.

                    Abstraction

                    Abstraction means to ignore the unnecessary details of an object and access all the essential
                    details. Let’s understand the concept with an example. When you do online shopping you
                    simply order the item and pay for it. So, here the user is concerned about the payment and
                    shopping. He never comes to know the background process. Classes use this concept and

                    represent essential properties of the objects.

                    Encapsulation

                    The wrapping of data and functions in an object or class is known as encapsulation. It prevents
                    the data from unauthorised access and from getting misused. Encapsulation ensures that the
                    user cannot access the data without proper authorisation. Let’s understand the concept with
                    an example.
                    Suppose you go to an automatic cola vending machine and request for a cola. The machine

                    processes your request and gives you cola.
                    Here, the automatic cola vending machine is a class. It contains both data, i.e., cola can, and
                    operations, i.e., service mechanism and they are wrapped/integrated under a single unit, cola
                    vending machine. This is called encapsulation.

                    Inheritance

                    Inheritance is one such concept where the properties of one class can be inherited by the
                    other. A class which inherits the properties is known as child class whereas a class whose




                     54
   61   62   63   64   65   66   67   68   69   70   71