Chapter 5 : Data Types -I

PCBWay

Q.1: Which of the following is not a primitive?

DRex Electronics

A. int
B. byte
C. char
D. number

Answer : D

Q.2: What is the size of char data type (in bytes)?

A.1
B. 2
C. 4
D. 8

Answer : B

Q.3: How much memory does short data type consume (in bytes)?

A. 4
B. 2
C. 1
D. 8

Answer : B

Q.4: Which of the following is not a primitive?

A. long
B. double
C. boolean
D. String

Answer : D

Q.5: What is the size of byte variable (in bytes)?

A. 4
B. 1
C. 2
D. 8

Answer : B

Q.6: How much memory does long variable take (in bytes)?

A. 2
B. 4
C. 8
D. 16

Answer : C

Q.7: ……….. Is the default integer type.

A. INT
B. byte
C. long
D. number

Answer : A

Q.8: ……….. is the default floating type.

A. short
B. float
C. double
D. single

Answer: C

Q.9: Which of the following is not a primitive ?

A. short
B. float
C. single
D. double

Answer : C

Q.10: How much memory does int data type take (in bytes)?

A. 2
B. 8
C. 16
D. 4

Answer : D

Q.11: Which of the following type is signed?

A. byte
B. int
C. double
D. All of the above

Answer : D

Q.12: What is the default value of a Boolean variable ?

A. true
B. false
C. Null
D. Junk

Answer : B

Q.13: What is the output ?

class program {

public static void show () {

byte b = -128;

System.out.println(“Byte value:”+b);

}

public static void main(string args[]){

show();

}

}

A. -128
B. Compiler error
C. Runtime error
D. 0

Answer : A

Q.14: Which of the following is not a primitive ?

A. Object
B. int
C. boolean
D. char

Answer : A

Q.15: What is the output ?

class program {

public static void show () {

byte b ;

System.out.println(“Byte value:”+b);

}

public static void main(string args[]){

show();

}

}

A. false
B. true
C. Compiler error
D. Runtime error

Answer : C

Q.16: What is the output ?

class program {

public static void show () {

byte b = -129;

System.out.println(“Byte value:”+b);

}

public static void main(string args[]){

show();

}

}

A. -129
B. Runtime error
C. Compiler error
D. 1

Answer : C

Q.17: Identify the invalid data type ?

A. float
B. double
C. number
D. byte

Answer : C

Q.18: Identify the reference data type?

A. int
B. long
C. string
D. object

Answer : C.D

Q.19: What is the output ?

class program {

public static void show () {

float f = 12.23

System.out.println(“Float value:”+f);

}

public static void main(string args[]){

show();

}

}

A. 12.23
B. 12
C. Runtime error
D. Compiler error

Answer : D

Q.20: What is the output ?

class program {

public static void show () {

double f = 12.23

System.out.println(“Double value:”+f);

}

public static void main(string args[]){

show();

}

}

A. 12.23
B. 12
C. Runtime error
D. Compiler error

Answer : A

Q.21: What is the output ?

class program {

public static void show () {

float f = 12.23f;

int i = 20;

i = i*f;

System.out.println(“Result:”+i);

}

public static void main(string args[]){

show();

}

}

A. 244
B. 200
C. compiler error
D. runtime error

Answer : C

Q.22: What is the output ?

class program {

public static void show () {

byte b = 10;

int i = 20;

i = i*b;

System.out.println(“Result:”+i);

}

public static void main(string args[]){

show();

}

}

A. 200
B. 10
C. compiler error
D. runtime error

Answer : A

Q.23: What is the output ?

class program {

public static void show () {

byte b = 10;

int i = 20;

b = i*b;

System.out.println(“Result:”+b);

}

public static void main(string args[]){

show();

}

}

A. 244
B. 200
C. compiler error
D. runtime error

Answer : C

Q.24: What is the output ?

class program {

public static void show () {

float f = 10.23;

int i = 20;

f = i*f;

System.out.println(“Result:”+f);

}

public static void main(string args[]){

show();

}

}

A. runtime error
B. compiler error
C.  202
D. 202.6

Answer : B

Q.25: What is the output ?

class program {

public static void show () {

float f = 12.23f;

int i = 20;

f = i*f;

System.out.println(“Result:”+f);

}

public static void main(string args[]){

show();

}

}

A. 244.5599
B. 12.23
C.  Runtime error
D. Compiler error

Answer : A

Q.26: What is the output ?

class program {

public static void show () {

short sh;

System.out.println(“Short value:”+sh);

}

public static void main(string args[]){

show();

}

}

A. 0
B. Null
C. Compiler error
D. Runtime error

Answer : C

Q.27: What is the output ?

class program {

public static void mixedOps() {

float f = 10.10f;

int j = 20;

j = (int) f * j;

System.out.println(j);

}

public static void main(string args[]){

mixedOps();

}

}

A. Runtime error
B. Compiler error
C. 100
D. 100.00

Answer : C

Q.28: What is the default value of long variable?

A. Junk
B. Null
C. 0
D. -1

Answer:  C

Q.29: What is the output ?

class program {

public static void mixedOps() {

float f = 2.2;

double d = 3.3;

f= f * d;

System.out.println(“Result:” +f );

}

public static void main(string args[]){

mixedOps();

}

}

A. 6.6
B. 7.26
C. Runtime error
D. Compiler error

Answer : C

Q.30: What is the output ?

class program {

public static void mixedOps() {

float f = 2.2f;

double d = 3.3d;

d= f * d;

System.out.println(“Result:” +d);

}

public static void main(string args[]){

mixedOps();

}

}

A. 6.6
B. 7.26
C. Runtime error
D. Compiler error

Answer : B

Q.31: What is the output ?

class program {

public static void mixedOps() {

float f = 2.2f;

double d = 3.3d;

f= f * d;

System.out.println(f );

}

public static void main(string args[]){

mixedOps();

}

}

A. 7.26
B. 6.6
C. Runtime error
D. Compiler error

Answer : D

Q.32: What is the output ?

class program {

public static void mixedOps() {

boolean b = true;

int i =10;

i=(int)b*i;

System.out.println(“Result:” +i );

}

public static void main(string args[]){

mixedOps();

}

}

A. Runtime error
B. Compiler error
C. 10
C. 11

Answer : B

Q.33: What is the output ?

class program {

public static void mixedOps() {

boolean b = true;

int i =10;

b=(boolean)i*b;

System.out.println(“Result:” +b );

}

public static void main(string args[]){

mixedOps();

}

}

A. true
B. flase
C. Compiler error
D. Runtime error

Answer : C

Q.34: Which data type size is 2 bytes ?

A. char
B. short
C. int
D. long

Answer : A,B

Q.35: Which data type size is 1 byte?

A. boolean
B. byte
C. int
D. char

Answer : B

Q.36: Which data type size is dependent on JVM ?

A. long
B. double
C. float
D. boolean

Answer : D

Q.37: Which data type occupies 8 bytes?

A. short int
B. int
C. long int
D. long

Answer : D

Q.38: Which data type occupies 4 bytes ?

A. int
B. double
C. long
D. float

Answer : A,D

Q.39: What is the output ?

class program {

public static void mixedOps() {

float f = 10.10f;

int j =10;

f=(int)f*j;

System.out.println(“Result:” +f );

}

public static void main(string args[]){

mixedOps();

}

}

A. 100
B. 100.0
C. Compiler erroe
D. Runtime error

Answer : B

Q.40: What is the output ?

class program {

public static void mixedOps() {

float f = 10.10f;

int j =10;

f=(float)f*j;

System.out.println(“Result:” +f );

}

public static void main(string args[]){

mixedOps();

}

}

A. 100
B. 101
C. 100.0
D.101.0

Answer : D

Q.41: Identify the correct statement.

A. boolean variable can be casted to int
B. int value can be casted to boolean
C. float variable can be casted to boolean
D. float variable can be casted to int

Answer : D

Q.42: Which data types occupies 8 bytes?

A. float
B. long float
C. double
D. long

Answer : C,D