Page 116 - CA_Blue( J )_Class9
P. 116

4.  +, -, * etc are ___________ operators.
                         a.  Unary                                      b.  Binary
                         c.  Arithmetic                                 d.  Both b and c
                      5.  What will be the output?
                         int a=5,b;
                         b=++a;
                         System.out.println(++b);
                         a.  5                                          b.  6
                         c.  7                                          d.  8

                   Answers
                   1. a       2. b     3. c     4. b     5. c


                                                                                                 21 st
                  E.  Case Study.                                                              Century   #Experiential Learning
                                                                                                 Skills
                      You are tasked with developing a Java program that simulates a website's page views. Every time a user visits a particular
                      page, you need to increment a counter to keep track of the number of views for that page.
                      1.  In Java, what is the purpose of initializing a counter variable?
                         a.  To ensure the variable is available for garbage collection.
                         b.  To prevent the counter from starting with an undefined value.
                         c.  To create a constant value that doesn't change.
                         d.  To avoid compilation errors.

                      2.  Which of the following is the correct way to initialize a counter variable in Java?
                         a.  int counter = "0";                         b.  int counter = 0;
                         c.  counter = 0;                               d.  int counter;
                      3.  Given the following Java code, what will be the value of counter after execution?
                         int counter = 0;
                         for(int i = 0; i < 3; i++) {
                             counter++;
                         }
                         a.  0                                          b.  2
                         c.  3                                          d.  4
                      4.  What is the consequence of not initializing a counter variable in Java?
                         a.  The variable will automatically be set to 0.
                         b.  The compiler will throw an error.
                         c.  The counter will increment from the previous value used by the memory location.
                         d.  The program will crash during runtime.


                   Answers
                   1. b       2. b     3. c     4. b



                  F.  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.


                   114    Touchpad Computer Applications-IX
   111   112   113   114   115   116   117   118   119   120   121