Here are multiple-choice questions (MCQs) on wrapper classes in Java:
Question 1
What is the purpose of wrapper classes in Java?
A) To wrap primitive data types into objects.
B) To handle I/O operations.
C) To manage exceptions.
D) To perform arithmetic operations.
Answer: A) To wrap primitive data types into objects.
Question 2
Which wrapper class corresponds to the primitive type int?
A) Double
B) Character
C) Integer
D) Float
Answer: C) Integer
Question 3
Which of the following is NOT a wrapper class in Java?
A) Integer
B) Double
C) Boolean
D) List
Answer: D) List
Question 4
How do you convert a primitive int to an Integer object?
A) Integer i = new Integer(10);
B) Integer i = 10;
C) Integer i = int(10);
D) Integer i = Integer.parseInt(10);
Answer: A) Integer i = new Integer(10);
Question 5
Which method of the Integer class converts a string to an integer?
A) Integer.toString()
B) Integer.parseInt()
C) Integer.valueOf()
D) Integer.convert()
Answer: B) Integer.parseInt()
Question 6
Which of the following statements is true about the Double wrapper class?
A) Double is used to wrap primitive float values.
B) Double provides methods to convert between double and String.
C) Double can only be used with double literals.
D) Double has a method called doubleValue() that returns a float.
Answer: B) Double provides methods to convert between double and String.
Question 7
Which method returns the primitive boolean value from a Boolean object?
A) booleanValue()
B) getBoolean()
C) toBoolean()
D) parseBoolean()
Answer: A) booleanValue()
Question 8
What is the default value of a wrapper class object when it is declared as a field in a class?
A) null
B) 0
C) false
D) NaN
Answer: A) null
Question 9
How do you create a Character object from a primitive char value?
A) Character c = new Character('a');
B) Character c = 'a';
C) Character c = Character.valueOf('a');
D) Character c = Character.parseChar('a');
Answer: A) Character c = new Character('a');
Question 10
Which wrapper class provides a constant for the maximum value of its type?
A) Integer
B) Boolean
C) Double
D) Character
Answer: A) Integer
Question 11
Which of the following is NOT a method provided by the Float wrapper class?
A) floatValue()
B) toString()
C) parseFloat()
D) getFloat()
Answer: D) getFloat()
Question 12
What is the result of calling Integer.parseInt("123")?
A) 123.0
B) 123
C) null
D) Integer("123")
Answer: B) 123
Question 13
How can you convert a Boolean object to a primitive boolean value?
A) Boolean.toPrimitive()
B) Boolean.getValue()
C) Boolean.booleanValue()
D) Boolean.parseBoolean()
Answer: C) Boolean.booleanValue()
Question 14
Which method of the Character class checks if a character is a digit?
A) Character.isDigit()
B) Character.isNumber()
C) Character.isDigitOrLetter()
D) Character.isNumeric()
Answer: A) Character.isDigit()
Question 15
Which wrapper class is used to represent a float data type?
A) Float
B) Double
C) Long
D) Integer
Answer: A) Float
Question 16
Which method of the Integer class returns the integer value represented by the specified string argument?
A) Integer.parseInt()
B) Integer.toInt()
C) Integer.valueOf()
D) Integer.getValue()
Answer: A) Integer.parseInt()
Question 17
Which of the following methods is used to compare two Double objects?
A) Double.compare()
B) Double.equals()
C) Double.compareTo()
D) Double.isEqual()
Answer: A) Double.compare()
Question 18
How do you obtain the primitive long value from a Long object?
A) longValue()
B) getLong()
C) toLong()
D) Long.valueOf()
Answer: A) longValue()
Question 19
What is the maximum value that can be held by an Integer wrapper class?
A) 2147483647
B) Infinity
C) 127
D) Double.MAX_VALUE
Answer: A) 2147483647
Question 20
Which wrapper class provides the method toString() to convert its value to a String?
A) Integer
B) Boolean
C) Double
D) All of the above
Answer: D) All of the above
No comments:
Post a Comment