Page 361 - CA_Blue( J )_Class10
P. 361

7.  What does a class encapsulate?                                                              [2013]
                   Ans.  A class encapsulates two things which are data members and methods.
                    8.  Differentiate between public and private modifiers for members of a class.                  [2012]
                   Ans.
                                      public modifier                                 private modifier
                        Data members can be accessed from anywhere.  Data members can be access from the same class only.
                        By default, all data members are public.  To make data members private, we have to use the keyword private.
                    9.  In the program given below, state the name and the value of the:                            [2012]
                       (i)   method argument or argument variable     (ii)  class variable
                       (iii)   local variable
                            class MyClass{
                                static int x = 7;
                                int y = 2;
                                public static void main(String args[]){
                                    MyClass obj = new MyClass();
                                    System.out.println(x);
                                    obj.sampleMethod(5);
                                    int a = 6;
                                    System.out.println(a);
                                }
                                void sampleMethod(int n){
                                    System.out.println(n);
                                    System.out.println(y);
                                }
                            }
                   Ans.  (i) Method argument is n, and its value is 5.      (ii) Class variable is x, and its value is 7.
                       (iii) Local variable is a, and its value is 6.















































                                                                                                                       359
                                                                                           Encapsulation and Inheritance   359
   356   357   358   359   360   361   362   363   364   365   366