Page 284 - CA_Blue( J )_Class10
P. 284

8.  Which of the following best describes encapsulation in the context of a class?
                    a.  A class's ability to inherit properties from another class
                    b.  Bundling data and methods that operate on that data within one unit
                    c.  The creation of multiple objects from a single class
                    d.  The ability to redefine methods in a subclass
                  9.  What is the term for a function defined inside a class in object oriented programming?
                    a.  Method                                      b.  Attribute
                    c.  Constructor                                 d.   Destructor
                 10.  In object oriented programming, what is inheritance?
                    a.  The process of creating a new class from an existing class
                    b.  A way to protect data from unauthorized access
                    c.  A mechanism for ensuring that a class has a single instance
                    d.  A way to hide the implementation details of a class

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


              B.  Fill in the blanks.
                  1.  A ………………… is like a method that has the same name of the class.
                  2.  Every class component is wrapped within ………………….
                  3.  The ………………… data members or the member methods can be accessed from anywhere either within the class or outside the
                    class.
                  4.  When a class is declared within another class then it is called a ………………… class.
                  5.  The ………………… keyword denotes the current class’s object.

                Answers
                1. Constructor      2. Curly brackets     3. public      4. Nested      5. this



              C.  Answer the following questions:
                  1.  Define a class. How it is declared?
                Ans.  In Java, Classes are non-primitive data types that act as a blueprint for creating objects of the same type. In other words, they are
                     a set of instructions to build a specific type of object.
                     Declaration of a class
                     class sum // <classname>
                     {
                         <data members>
                         int a,b;
                         <member methods>
                         void display()
                         {   System.out.println("Class and Object Program");
                         }
                     }
                  2.  What is an object? Write the statement to create an object of a class.
                Ans.  An object is a fundamental unit of object-oriented programming. Following is the syntax to create an object:
                     <class_name> <object_name> = new <constructor>();
                     sum ob = new sum();








                282282  Touchpad Computer Applications-X
   279   280   281   282   283   284   285   286   287   288   289