Page 141 - Cs_withBlue_J_C11_Flipbook
P. 141

2.  Why boolean data type cannot be converted to any other data type using the concept of implicit or explicit data type conversion?
                   Ans.  The boolean data type is not compatible with any other primitive data types. So, it cannot be converted to any other type or vice
                       versa neither by implicit nor explicit data type conversion.
                    3.  What is narrowing?
                   Ans.  The process of assigning a value of a larger data type to a smaller data type using the concept of explicit data conversion is known
                       as narrowing.
                    4.  What type of conversion does the following program snippet exhibit?

                       char ch='A';
                       int n=ch;
                   Ans.  Implicit type conversion
                    5.  What is type conversion?
                   Ans.  The process of changing the value of one type value to another type is known as Type Conversion. It is also known as type
                       casting.
                    6.  What is the difference between Pure Arithmetic Expression and Mixed Arithmetic Expression?
                   Ans.  The difference between them is as follows:

                                     Pure Arithmetic Expression                      Mixed Arithmetic Expression
                       When  the  variables and constants in an expression  are  of  When the  variables and constants in  an expression  are  of
                       the  same  data  types,  then  the  expression  is  known  as  Pure  different data types, then the expression is known as Mixed
                       Arithmetic Expression.                            Arithmetic Expression.

                       For example:                                      For example:
                       double dia=34,r,pi=3.142,ar_circle;               int a=5;
                       r=34/2.0;                                         char ch='a';
                       ar_circle=pi*r*r;                                 double sum = a+ch;
                       System.out.println("Area of circle "+ar_ System.out.println("Result : " + sum);
                       circle);                                          //Output: Result : 102.0
                       //Output : Area of circle  908.038

                    7.  What is a String?
                   Ans.  A string is a sequence of characters stored in a single variable. The characters are written within “ ” (double quotation marks).
                    8.  What is the size of long and byte data type in bits?
                   Ans.  The size of the long data type is 64 bits and the byte data type is 8 bits.
                    9.  What is the use of \t and \n escape sequence?
                   Ans.  The use of:
                       •  \t is used to insert a horizontal tab.
                       •  \n is used to insert a new line.
                    10.  What is the difference between Static and Dynamic initialisation?
                   Ans.                Static initialisation                           Dynamic initialisation

                       When a constant is directly assigned to a variable, it is known  When a variable is initialised during the execution/run time of
                       as Static Initialisation.                       the program, then it is known as Dynamic Initialisation.

                       For example:                                    For example:
                       int a=6;                                        int a=5, b=6, c;
                       String n="Name";                                c=a+b;
                                                                       System.out.println(c);









                                                                                                                       139
                                                                         Primitive Values, Wrapper Classes, Types and Casting   139
   136   137   138   139   140   141   142   143   144   145   146