Page 360 - CA_Blue( J )_Class10
P. 360

double value = 3.14;
                    String str = Double.toString(value); // Convert double to String
                  i.  Which of the following statements regarding converting primitive data types to strings in Java is true based on the provided
                    paragraph?
                     Statement 1: The String.valueOf() method can only convert primitive data types to strings.
                     Statement 2: toString() methods provided by wrapper classes can convert primitive data types to strings.
                    a.  Statement 1 is true, and Statement 2 is false.   b.  Statement 1 is false, and Statement 2 is true.
                    c.  Both Statement 1 and Statement 2 are true.   d.  Both Statement 1 and Statement 2 are false.
                  ii.  What does the String.valueOf() method do in Java?
                    a.  Converts strings to primitive data types
                    b.  Converts primitive data types to strings
                    c.  Converts wrapper classes to primitive data types
                    d.  Converts primitive data types to wrapper classes
                 iii.  Which method can convert different types of values, including primitive data types, to their string representations?
                    a.  toString()                                  b.  valueOf()
                    c.  getString()                                 d.  parseString()
                  2.  Answer from the program snippet?
                    int value = 123456789L;
                    String str = String.valueOf(value); // Convert long to String
                    double parsedValue = Double.parseDouble(str); // Parse String to double
                  i.  What is the purpose of the String.valueOf() method in the given code?
                    a.  Converts a string to a long value           b.  Converts a long value to a string
                    c.  Parses a string to a double value           d.  Parses a double value to a string
                  ii.  What does the Double.parseDouble() method do in the given code?
                    a.  Converts a string to a double value         b.  Converts a double value to a string
                    c.  Converts a long value to a double value     d.  Converts a double value to a long value
                 iii.  What is the error in the program?
                    a.  double parsedValue = Double.parseDouble(str);   b.  String str = String.valueOf(value);
                    c.  int value = 123456789L;                     d.  None of these

                                          Previous Years' Questions


                  1.  What is inheritance?                                                                        [2017]
                Ans.  Inheritance in Java is the method which allows one class to inherit the properties (data members and member methods) of
                    another class.
                  2.  Define encapsulation.                                                                       [2016]
                Ans.  The wrapping up of data members and member methods together into a single unit is called encapsulation.
                  3.  Name any two types of access specifiers.                                                    [2016]
                Ans.  Two types of access specifiers are public and private.
                  4.  The access specifier that gives the most accessibility is ………… and the least accessibility is ………….   [2015]
                Ans.  public, private
                  5.  Consider the following class:                                                               [2014]
                    public class myClass{
                        public static int x = 3, y = 4;
                        public int a = 2, b = 3;
                    }
                    (i)  Name the variables for which each object of the class will have its own distinct copy.
                    (ii) Name the variables that are common to all objects of the class.
                Ans.  (i)  a and b                           (ii) x and y
                  6.  State the Java concept that is implemented through:                                         [2013]
                    (i)  a superclass and a subclass.
                Ans.  Inheritance


                358358  Touchpad Computer Applications-X
   355   356   357   358   359   360   361   362   363   364   365