Page 285 - ComputerScience_Class_11
P. 285

7.  Any change made to a ………………… through an object will affect the common data member of all objects.
                    8.  ………………… are also known as mutators and cause a change in the state of the object.
                 C.  Answer the following questions:

                    1.  What is the difference between Method Header and Method Signature?
                    2.  What are the advantages of using a method?
                    3.  Write the general syntax of declaring a method.
                    4.  What is the difference between Return Type and Return Statement?
                    5.  Write the two characteristics of Return Statement.
                    6.  What is Method Overloading? How does the compiler differentiate between methods which are overloaded?
                    7.  What are access specifiers in Java? Explain public, private and protected access specifiers with examples.
                    8.  What is the difference between Actual Parameter and Formal Parameter?

                 D.  Higher Order Thinking Skills (HOTS)
                    1.  A method takes an integer value, performs calculations and returns a result without modifying the original value passed to it.
                       Another method modifies the values of an array passed to it. Differentiate between these two methods based on their behaviour
                       and side effects.
                    2.  A constructor is used to initialise instance variables when an object is created. Justify why constructors do not have a return type
                       and are automatically invoked.

                 E.  Case study-based questions.

                    Priya is developing a Java program for a school library to manage book records. Each book has a book ID, title and number of copies
                    available. When a new book record is created, the program automatically assigns default values to the number of copies using a
                    special method that has the same name as the class.
                    To display book details, Priya creates a user-defined method that prints the information of a book. The program also includes
                    another method with the same name but different parameters to display either basic book details or complete book information.
                    While testing, Priya observes that when book data stored in an object is passed to a method, changes made inside the method are
                    reflected in the original object. This helps her update the number of available copies when books are issued or returned.
                    Based on the given case, answer the following questions:
                    1.  Which method assigns default values when a book object is created?
                       a.  User-defined method                         b.  Main method
                       c.  Constructor                                 d.  Static method

                    2.  Which concept is used when two methods have the same name but different parameters?
                       a.  Inheritance                                 b.  Method overloading
                       c.  Method overriding                           d.  Encapsulation
                    3.  Why do changes made inside the method affect the original book object?
                       a.  Because a copy of values is passed          b.  Because the same memory location is shared
                       c.  Because the method is static                d.  Because the return type is void
                    4.  Which type of parameter passing is used when objects are passed to methods?
                       a.  Pass by value                               b.  Pass by reference
                       c.  Call by name                                d.  Call by result
                    5.  Why is a user-defined method used to display book details?
                       a.  To increase execution time                  b.  To reduce program readability
                       c.  To organise and reuse code                  d.  To restrict object creation


                 F.  Write the java program for the following:
                    1.  Design a class to overload a function geometry() with the specifications given as follows:
                        void geometry(int n, char ch) : With one integer argument and one character argument that draws a filled square of side n
                       using the character stored in ch




                                                                                           Methods and Constructors  283
   280   281   282   283   284   285   286   287   288   289   290