Page 275 - IT-802_class_12
P. 275

7.  What are methods in Java? Write a user defined method that return product of two numbers.   [CBSE Sample Paper 2022]
               8.  i.  How can we enable assertions to debug our code in java?                 [CBSE Sample Paper 2022]
                  ii.  What are the two ways to create threads in java?
                  iii. Which member function of the Integer wrapper class allows access to the int value held in it.

            C.  Competency-based/Application-based question:                                       Computational thinking
                Rahul has written the following code in Java. When he runs the code to see the output, the computer shows some errors.
               Rectify the errors and help him to get the correct output.

                int a=11, b=22, c
               c = a + b + a++ + b++ + ++a + ++b;
               System.out.println(“c = “+c)







            Lab aCtiVity
                                                                                           Subject Enrichment
                                                                                           Computational thinking
            Activity 1:
                  Write a program in Java to implement the formula.                           [CBSE Handbook]
                  area = length * width * height
            Activity 2:
                  Write a program in Java to find the result of the following expressions.    [CBSE Handbook]
                  (Assume a = 20 and b = 30)
                 i.  a%b                                            ii.  a /= b
                 iii. (a + b * 100) /10                             iv.  a && b
                 v.  a++
            Activity 3:
                  Write a program in Java to print the square of every alternate number of an array.   [CBSE Handbook]
            Activity 4:
                  Write a program in Java to create class Triangle with the data members  base, height, area and color. The members
                 base, height, area are of type double and color is of type string. Write getter and setter methods for base, height
                 and color, and write method to compute_area (). Create two object of class Triangle, compute their area, and
                 compare their area and color. If area and color both are same for the objects then display “Matching Triangles”
                 otherwise display “Non matching Triangles”.                                  [CBSE Handbook]
            Activity 5:
                  Write a program in Java to enable user to handle divide by zero exception.   [CBSE Handbook]



            Previous Years’ Questions



              1.  ……………………… symbol replaces a single character while matching a pattern with LIKE keyword.     [2023]
             Ans.  underscore (_)
              2.  ……………………… statement in Java, allows to use a prebuilt class and its associated methods from a package.   [2023]

                  (a)  include                                 (b)  public
                  (c)  extend                                  (d)  import
             Ans.  (d)  import
                                                                               Fundamentals of Java Programming  273
   270   271   272   273   274   275   276   277   278   279   280