Page 250 - CA_Blue( J )_Class10
P. 250

8.  What is the benefit of using user-defined methods in Java?
                     a.  Reduces code duplication and increases reusability   b.  Increases complexity of the program
                     c.  Decreases the execution speed              d.  Makes the program harder to understand
                  9.  Which of the following is the correct syntax for a method declaration in Java?
                     a.  `public static void myMethod() {}`         b.  `static void my Method() {}`
                     c.  `void myMethod(integer x) {}`              d.  `void int myMethod() {}`
                 10.  Can a method call itself in Java?
                     a.  Yes, but only if it's a static method      b.  No, it leads to a compilation error
                     c.  Yes, it's called recursion                 d.  Yes, but only if it's a public method

              B.  Fill in the blanks.
                  1.  ………………… occupy less space in memory and the execution becomes faster.
                  2.  Every method should be provided with a …………………, so that it can be called from same class or different classes.

                  3.  Some methods are already defined in the packages of Java which are known as ………………… methods.
                  4.  By default, the ………………… statement always returns a single value of one data type only.
                  5.  Only ………………… data can be used in Pass by value.

              C.  Assertion and Reasoning based questions:
                     The following questions consist of two statements – Assertion (A) and Reason (R). Answer these questions by selecting the
                     appropriate option given below:
                     a.  Both A and R are true, and R is the correct explanation of A.
                     b.  Both A and R are true, but R is not the correct explanation of A.
                     c.  A is true, but R is false.
                     d.  A is false, but R is true.
                   1.  Assertion (A): An impure method changes the state of an object.
                       Reason (R): If the variable in the formal parameter changes its value, then the variable of the actual parameter also changes.
                    2.  Assertion (A): A method written by the programmer according to his requirements is known as a user-defined method.
                       Reason (R): It helps a programmer to write customised code according to the needs of a program.
                  3.  Assertion (A): In Java, a method can be called from another method without using an object.
                     Reason (R): Static methods can be called without creating an instance of the class.
                  4.  Assertion (A): Recursion is a technique where a method calls itself.

                     Reason (R): Recursion can be used to solve problems that involve circular references.
                  5.  Assertion (A): User-defined methods must always return a value in Java.
                     Reason (R): Methods in Java can be designed to perform actions without returning any value by using the void keyword.
                                                                                                21 st
              D.  Case-based questions.                                                      Century   #Experiential Learning
                                                                                               Skills
                     Rani is working on a Java program that calculates the area of different shapes. She decides to create user-defined methods for
                     calculating the area of a circle, a rectangle, and a triangle.
                     class Areacal {
                         double areaOfCircle(double radius) {
                             return Math.PI * radius * radius;
                         }
                         double areaOfRectangle(double length, double breadth) {
                             return length * breadth;
                         }
                         double areaOfTriangle(double base, double height) {


                248248  Touchpad Computer Applications-X
   245   246   247   248   249   250   251   252   253   254   255