0% found this document useful (0 votes)
62 views

Primitive Values, Wrapper Classes, Types and Casting

Uploaded by

Arvind Bhatnagar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views

Primitive Values, Wrapper Classes, Types and Casting

Uploaded by

Arvind Bhatnagar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Primitive values, Wrapper

classes, Types and casting

Multiple choice questions 11. If anything is to be remembered by the computer,


what will be required during program execution?
1. First four data types hold- It should be stored in the memory of the computer.
(a) Real numbers (b) Integers What will be that?
(c) Single character (d) Whole numbers (a) Variables (b) Literals
2. Next two data types hold- (c) Comments (d) Operators
(a) Real numbers (b) Integers 12. Which address of the location in memory is
(c) Single character (d) Whole numbers needed if we want to refer a data in machine
language?
3. From the Unicode character set, what does a
character data type hold ? (a) Numerical (b) Alpha numerical

(a) Real numbers (b) Integers (c) Alphabetical (d) Real

(c) Single character (d) Word 13. Language in which names are used instead of
numerical address of the memory location to refer
4. Data types used in Java are also called:
to data is :
(a) Fixed Data Types
(a) Low level (b) Middle level
(b) Ancient Data Types
(c) High level (d) Top level
(c) Primitive Data Types
14. If we use a name to refer to the data stored in the
(d) New Data Types memory, it is called?
5. Elements which are machine independent in Java: (a) Variable (b) Literal
(a) Data types (b) Variables (c) Comment (d) Operator
(c) Literals (d) Characters 15. Where do we declare variables in Java?
6. In Java what are adaptable with IEEE 754? (a) Beginning (b) Initial
(a) Real numbers (b) Integers (c) Declaration (d) Comment
(c) Single character (d) Corrective 16. To be specified by user in conventional syntax, an
7. Which character set is used in Java: item should not be enclosed with:
(a) Numerical (b) IEEE (a) Curly bracket (b) Square brackets
(c) Character (d) Integer (c) Angle brackets (d) Round bracket
8. How many bits of precision are there in char type? 17. The list of item should not have ______ if separated
(a) 13 (b) 14 by commas in conventional syntax.
(c) 15 (d) 16 (a) Curly bracket (b) Square brackets
9. Which data type is not a number ? (c) Angle brackets (d) Round bracket
(a) Char (b) Real 18. Lists containing more than one item can be
(c) Boolean (d) Integer separated by:
10. Which element manipulates the data that is stored (a) Using semi colon
in memory? (b) Using commas
(a) Information (b) Programs (c) Using full stops
(c) Comments (d) Characters (d) Using Colon
19. Which is the incorrect statement while defining 29. Which of the following options are the method of
the variable name? heparin teacher for obtaining hash code for the
(a) It must begin with an alphabet underscore (_) invoking object?
(b) It must begin with a percentage sign (%) (a) int hash()
(c) No spaces are allowed in variables (b) int hashcode()

(d) It cannot be a reserved word (c) int hashCode()


(d) interger hashcode()
20. Which example of variable is correct?
30. Which is a super class of wrappers long ,character
(a) Int marks;
and integer?
(b) Double amount, interest
(a) Long (b) Digits
(c) Float rate;
(c) Float (d) Number
(d) All of these
31. Which is a wrapper for simple data type char?
21. In which type of statement Computer sets aside
(a) Float (b) Character
memory for the variable and associates the
(c) String (d) Integer
variables name with that memory ?
32. Which method of integer is used for converting
(a) Data type
the value of an object into int?
(b) Initial
(a) Bytevalue() (b) int intValue();
(c) Variable declaration statement
(c) int Bytevalue() (d) Byte Bytevalue()
(d) Comment
33. Which method is used to obtain value of invoking
22. What is used to determine the size of variable the
object as a long?
value it can hold and the operations that can be
(a) long value () (b) long longValue()
performed on it?
(c) Long longvalue() (d) Long Longvalue()
(a) Real numbers (b) Variables
34. What type of conversions are available in Java
(c) Data types (d) Floats
language?
23. Which classes are not included in Java.language ?
(a) Narrowing type conversion
(a) Byte (b) Integer
(b) Widening type conversion
(c) Array (d) Class
(c) A and B
24. Which of the following is a process of converting
(d) None of the above
the simple data type into a class?
35. Which of the following is higher data type in Java
(a) Type wrapping (b) Type conversion
language?
(c) Type casting (d) None of the above
(a) Data type which holds more data than other
25. Which of the following class is a super class of
data types
wrappers double and integer?
(b) Order type whose size is more than other data
(a) Long (b) Digits
type
(c) Float (d) Number
(c) 
Order type which can hold more precision
26. Which is a wrapper for simple data type float? digits than other data type
(a) Float (b) double (d) All of the above
(c) float (d) Double 36. Widening type conversion in Java includes?
27. Which method is a method of wrapper float for (a) Conversion of data from higher data type to
converting the value of an object into byte? lower data type
(a) bytevalue() (b) byte bytevalue() (b) Conversion of data from lower data type to
(c) byteBytevalue() (d) Bytevalue() higher data type
28. Which is a wrapper for data type int? (c) Conversion of data from any data type to any
(a) Integers (b) Long data type
(c) Byte (d) Double (d) None of the above
37. Narrowing type conversion in Java includes? 45. A boolean literal in Java can be type casted to
(a) Conversion of data from lower data type to _______ data type.
higher data type (a) Byte (b) Short
(b) Conversion of data from a higher data type to (c) Int (d) None of the above
lower data type
46. If a variable or operand in an expression is type
(c) Conversion of data from any data type to any
long then all the brands are type promoted to
data type
________ data type.
(d) None of the above
(a) Int (b) Long
Fill in the blanks (c) Float (d) Double
47. Java is an object oriented programming language
38. ________ is the result of a narrowing type
developed by ________ .
conversion.
(a) Loss of data (b) Addition of data (a) Oracle

(c) Corruption of data (d) None of the above (b) Sun Microsystems

39. _________ is the result of widening type (c) UNIX


conversion in Java. (d) Netscape
(a) Loss of data (b) Gain of data
Match the following
(c) No change (d) None of the above
40. Type promotion in Java uses only ________ . 48. Match the columns:
(a) Narrowing type conversion Group A Group B

(b) Widening type conversion 1. Java program is (i) Native


composed of
(c) No type conversion
2. Code is faster to (ii) classes
(d) None of the above
execute
41. Type casting in Java uses _______ type conversion. 3. Java provides (iii) slow execution
(a) Narrowing type conversion tools speed
(b) Widening type conversion 4. Disadvantage of (iv) convert javabyte
(c) No type conversion byte codes into native codes

(d) None of the above (a) 1-(ii), 2-(i), 3-(iv), 4-(iii)


(b) 1-(i), 2-(ii), 3-(iv), 4-(iii)
42. Explicit type conversion in Java refers to ________.
(c) 1-(ii), 2-(i), 3-(iii), 4-(iv)
(a) Narrowing type conversion
(d) 1-(ii), 2-(iv), 3-(i), 4-(iii)
(b) Widening type conversion
49. Match the columns:
(c) No type conversion
Group A Group B
(d) None of the above
1. Primitive (i) a class whose
43. Implicit type conversion in java is also called object wraps
________. 2. Wrapper classes (ii) data type
(a) Narrowing type conversion 3. Primitive types (iii) convert data
(b) Widening type conversion type to another
(c) No type conversion data type
4. User defined (iv) int, short, long,
(d) None of the above
casting byte
44. _________ are the compatible data types for type
(a) 1-(ii), 2-(i), 3-(iv), 4-(iii)
promotion or type casting.
(b) 1-(i), 2-(ii), 3-(iv), 4-(iii)
(a) byte, char , short (b) char. int, float
(c) 1-(ii), 2-(i), 3-(iii), 4-(iv)
(c) float. long , double (d) All of the above
(d) 1-(ii), 2-(iv), 3-(i), 4-(iii)
50. Match the columns: (b) Primitive data type and an object of a wrapper
Group A Group B class
1. Primitive data (i) 32 bit (c) Wrapper class
types (d) None of the above
2. int in java (ii) 8 54. Choose the correct output of the following Java
3. Signed (iii) byte Code:
4. Smallest integer (iv) int, short, long, int a=9;
type byte float b = a/2;
(a) 1-(ii), 2-(i), 3-(iv), 4-(iii) System.out.println(b);
(b) 1-(i), 2-(ii), 3-(iv), 4-(iii) (a) 4.0 (b) 4.5
(c) 1-(ii), 2-(i), 3-(iii), 4-(iv)
(c) 5.0 (d) None of the above
(d) 1-(ii), 2-(iv), 3-(i), 4-(iii)
55. Choose the correct output of the Java code
51. Match the columns: snippet?
Group A Group B char ch = ‘A’;//ASCII 65
1. Size of float and (i) int to long
int a = ch + 1;
double
ch = (char)a;
2. Automatic type (ii) 32 and 64
conversion System.out.println(ch);

3. Word true is (iii) double (a) 66 (b) A


4. Not an integer (iv) Boolean literal (c) B (d) 65
data type 56. Regarding the program code given below, answer
(a) 1-(ii), 2-(i), 3-(iv), 4-(iii) the questions that follow:
(b) 1-(i), 2-(ii), 3-(iv), 4-(iii) // char can be handled like integers
(c) 1-(ii), 2-(i), 3-(iii), 4-(iv) public class CharClass
(d) 1-(ii), 2-(iv), 3-(i), 4-(iii) {
52. Match the columns: public static void main(String args[])
Group A Group B {
1. Floating data type (i) string char myChar1 = ‘A’;
2. Character data (ii) double char myChar2 = ‘B’;
type cannot store System.out.println(“myChar1: “ +myChar1);
3. Range of byte data (iii) 4 byte System.out.println(“myChar2: “ +myChar2);
type }
4. Size of integer (iv) -128-127 }
(a) 1-(ii), 2-(i), 3-(iv), 4-(iii) (a) What will be the output?
(b) 1-(i), 2-(ii), 3-(iv), 4-(iii) (i) myChar1: A
(c) 1-(ii), 2-(i), 3-(iii), 4-(iv) myChar2: B
(d) 1-(ii), 2-(iv), 3-(i), 4-(iii) (ii) myChar1: B
myChar2: C
Programming based questions
(iii) myChar1: C
53. Choose the right statement: myChar2: D
int x = 25; (iv) myChar1: D
Integer y = new Integer(33); myChar2: E
What is the difference between these two (b) What is the name of the class?
statements? (i) System.out.println
(a) Primitive data types (ii) static void main()
(iii) public (a) What will be the output?
(iv) CharClass (i) myShort: 6000
57. Concerning the program code given below, (ii) myShort: 7000
answer the questions that follow:
(iii) myShort: 8000
public class ShortDataType
(iv) myShort: 4000
{
(b) What is the name of the data type used to store
public static void main(String args[])
myshort price?
{
short myShort = 6000; (i) ShortDatatype

System.out.println(“myShort: “ + myShort); (ii) static void main()


} (iii) public
} (iv) Short

Answers

Multiple choice questions 17. (a) Curly bracket


18. (b) Using commas
1. (b) Integers 19. (b) It must begin with a percentage sign (%)

Explanation: Integer. ,Floating-point number. 20. (d) All of these
Character. Boolean 21. (c) Variable declaration statement
2. (a) Real numbers 22. (c) Data types
3. (c) Single character 23. (c) Array
4. (c) Primitive Data Types 24. (b) Type conversion

Explanation: The eight primitives defined in Java Explanation: Syntax dataType variableName =
are int, byte, short, long, float, double, boolean, (dataType) variableToConvert;
and char – those aren’t considered objects and 25. (d) Number
represent raw values.
26. (a) Float
5. (a) Data types
27. (b) byte bytevalue()
6. (a) Real numbers 28. (a) Integers
7. (c) Character Explanation: The wrapper class in Java provides
8. (d) 16 the mechanism to convert primitive into object

Explanation: The char data type is a single 16-bit and object into primitive.
Unicode character. It has a minimum value of ‘\ 29. (c) int hashCode()
u0000’ (or 0) and a maximum value of ‘\uffff’ (or 30. (d) Number
65,535 inclusive). 31. (b) Character
9. (c) Boolean 32. (b) int intValue();

Explanation: The BOOLEAN data type stores 33. (b) long longValue()
TRUE or FALSE data values as a single byte.
34. (c) A and B
10. (b) Programs 35. (d) All of above
11. (a) Variables 36. (b) 
alteration of data from lower data type to
12. (a) Numerical higher data type
13. (c) High level 37. (b) alteration of data from a higher data type to
14. (a) Variable lower data type

Explanation: Syntax type variable = value;
Fill in the blanks
15. (a) Beginning
16. (c) Angle brackets 38. (a) Loss of data
39. (c) No change 51. (a) 1-(ii), 2-(i), 3-(iv), 4-(iii)
40. (b) Widening type conversion 52. (a) 1-(ii), 2-(i), 3-(iv), 4-(iii)
41. (a) Narrowing type conversion
Programming based questions
42. (a) Narrowing type conversion
43. (b) Widening type conversion 53. (b) Primitive data type and an object of a wrapper
44. (d) All of the above class
45. (d) None of the above 54. (a) 4.0
46. (b) Long 55. (c) B
47. (b) Sun Microsystems 56. (a) (i) myChar1: A
myChar2: B
Match the following
(b) (iv) CharClass
48. (a) 1-(ii), 2-(i), 3-(iv), 4-(iii) 57. (a) (i) myShort: 6000
49. (a) 1-(ii), 2-(i), 3-(iv), 4-(iii) (b) (iv) Short
50. (a) 1-(ii), 2-(i), 3-(iv), 4-(iii)

You might also like