Page 52 - CA_Blue( J )_Class10
P. 52

11.  Distinguish between implicit and explicit type conversion. Provide an example of each.
                 Ans.              Implicit Type Conversion                         Explicit Type Conversion
                     This conversion occurs while assigning a value of a smaller data  This conversion occurs while assigning a value of a larger data
                     type to a variable of a larger data type.       type to a variable of a smaller data type.
                     Conversion is automatically done by the compiler.  It requires user's intervention.
                     Example: Calculation of area of a circle.       Example: Calculation of sum of 2 numbers
                     float r = 4.5f ; double a=0.0;                  int sum = 0; double a = 4.5, b=2.0;
                     a= 3.142 * r * r;                               sum = (int)(a+ b);
                     System.out.println(a);                          System.out.println(sum);
                     Output:                                         Output: 6
                     55.42487496597301                               Here, though variables "a" and "b" are double and when it is
                     Here, the result is converted to "double" though "r" is a float  tried to keep in int variable, user's intervention is required.
                     variable automatically.
                 12.  Distinguish between static initialization and dynamic initialization.
                Ans.                 Static Initialization                           Dynamic Initialization

                     Direct assignment of a constant to a variable. Example:  Initializing a variable during the execution of a program.
                     int a;                                          Example:
                     a = 20;                                         float i1, i2, i3;
                                                                     i1=i2 + i3;
                 13.  What do you mean by a token?
                Ans.  Tokens are the smallest units of code that the Java compiler recognises as meaningful and syntactically correct.
                 14.  How is 'A' is different from "A"?
                Ans.  The difference between 'A' and "A" is:
                    'A' is a character literal whereas "A" is a String literal.
                 15.  Write down the data types for the following:
                    a.  Fractional Number                           b.  A small letter
                    c.  A sentence                                  d.  Long integer
                Ans.  a.  float or double                           b.  char
                     c.  String                                     d.  long
                 16.  Write down the data types in ascending order of size.
                    a.  byte                                        c.  long
                    b.  double                                      d.  short
                Ans.  byte < short < long < double

              D.  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): Implicit type conversion in Java can lead to loss of precision.
                     Reason (R): Implicit type conversion, also known as automatic type conversion or type promotion, occurs when the target type is
                    larger than the source type.
                  2.  Assertion (A): Escape sequences in Java are used to represent special characters within numerical values.
                     Reason (R): Escape sequences consist of a backslash \ followed by a character or a combination of characters.
                  3.  Assertion (A): In Java, it is not mandatory to initialize local variables before using them in a method, wherever required.
                     Reason (R): Local variables are variables declared within a method or block of code. Unlike instance variables, local variables do
                    not have default values and must be explicitly initialized before they can be used. If a local variable is not initialized before it is
                    accessed, the Java compiler will raise an error.
                Ans.  1. b    2. d    3. a

                5050  Touchpad Computer Applications-X
   47   48   49   50   51   52   53   54   55   56   57