Page 227 - computer science (868) class 11
P. 227

7.  Which of the following methods is called the Accessor Method?
                       a.  Pure method                                 b.  Impure method
                       c.  Mutator                                     d.  None of these
                    8.  What is the fundamental unit of object-oriented programming called?
                       a.  Class                                       b.  Object
                       c.  Method                                      d.  Data members
                    9.  How many types of access specifiers are used in Java?
                       a.  1                                           b.  2
                       c.  3                                           d.  4

                    10.  The class variables also known as ………………… .
                       a.  static data member                          b.  non-static data member
                       c.  instance variable                           d.  None of these

                  Answers
                      1.  d    2.  b     3.  b     4.  d    5.  b     6.  a     7.  a     8.  b     9.  c     10.  a


                 B.  Fill in the blanks:
                    1.  If there is more than one statement under a loop, we need to write the statements within ………………… .

                    2.  Every method should have a …………………, so that it can be called from the same class or different classes.
                    3.  The first line of any method definition is known as the ………………… .
                    4.  ………………… are blocks of statements in a program that perform a specific task and can be reused as and whenever required.
                    5.  The keyword ………………… allows only the methods to be accessed by the same class.
                    6.  A ………………… is a loop within a loop.
                    7.  An object is a ………………… unit of object-oriented programming.
                    8.  Defined methods in a class are termed as ………………… .

                    9.  ………………… are methods that have the same name as that of a class.
                    10.  The ………………… keyword is required to use the object of the class from the member method of the same class.

                  Answers
                    1.   curly braces    2.   method name     3.  Method Header     4.  Methods        5.   “Private”
                    6.   nested loop     7.   fundamental     8.  Member Methods    9.  constructors    10.   this

                 C.  Answer the following questions:

                    1.  Why are methods useful?
                   Ans.  The methods are useful as they:
                        (i)  reduce the size of the coding.
                       (ii)  reduce the burden of debugging programming code.
                        (iii)  occupy less space in memory and the execution becomes faster.
                    2.  What is the syntax of declaring a method?
                   Ans.  <access specifier> <return-type> <name-of-method> <parameter-list>
                       {  Job done by the method;                      }
                    3.  What is a Method Header? Give an example.
                   Ans.  The first line of any method definition is known as the Method Header or Method Prototype. The different parts it contains are
                       the Access Specifier, Return Data Type, Method Name and the Parameter List.
                       For example: public int twice (int n)
                    4.  What is an Access Specifier? Name the different Access Specifiers.
                   Ans.  An Access specifier defines how the data members and methods of a class can be accessed.
                       The three different access specifiers are public, private and protected.


                                                                                                                       225
                                                                                              Methods and Constructors  225
   222   223   224   225   226   227   228   229   230   231   232