Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 114 - 2617_JSSPS_C-7
P. 114

    WHAT IS AN OBJECT AND A CLASS?

                  As we have discussed above, an Object-Oriented Programming language uses objects and classes. Let
                  us discuss them in detail.

                  Object

                  An  object  can  be  defined  as  a  real-world  entity  such  as  a  telephone,  mouse  or  bag.  All  real-world
                  entities  have  properties  and  behaviours.  Properties  represent  the  physical  appearance  and  qualities
                  of an object. On the other hand, behaviour represents the functions that an object can perform.
                  For example, a computer has a brand name, type and price as its properties. It also has "calculation" as
                  one of its behaviours.

                  Class

                  A class can be defined  as a user-defined  blueprint  or prototype that is used to create  objects. It
                  contains objects that have similar properties and behaviour. For example, an animal class has
                  different types of animals.

                                                                   Animal

                                             Cat                    Tiger                    Dog

                  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.

                  NEED FOR METHODS

                  There is no use of a class without methods. Methods                         Definition
                  are necessary to perform operations on the data
                  members  of a class. These are very useful as they           Definition: A method in Java is a group of
                  reduce the size of a program. They occupy less space         statements which can be used together
                  in  memory and  the  execution  becomes faster. They         to perform a specific  operation. These
                  increase the reusability of code. They reduce the            can be used repeatedly, thus  reducing
                  burden of debugging of programming code, so finding          the length of code.
                  and  correcting  the errors becomes easy for the
                  developers.

                  FORMS OF METHODS

                  There are two forms of methods: predefined methods and user-defined methods. Let us study them
                  in detail.

                            Premium Edition-VII
                    112

| 109 110 111 112 113 114 115 116 117 118 119 |