Java Tutorial

Java Control Statements

Object Oriented Programming

Java Built-in Classes

Java File Handling

Java Error & Exceptions

Java Multithreading

Java Synchronization

Java Networking

Java Collections

Java List Interface

Java Queue Interface

Java Map Interface

Java Set Interface

Java Data Structures

Java Collections Algorithms

Java Miscellaneous

Advanced Java

Java APIs & Frameworks

Java Useful Resources

Java Mock Test



This section presents you various set of Mock Tests related to Java Framework. You can download these sample mock tests at your local machine and solve offline at your convenience. Every mock test is supplied with a mock test key to let you verify the final score and grade yourself.

Questions and Answers

Java Mock Test I

Answer : C

Explaination

Correct syntax is public static void main(String[] args).

Q 2 - Which of the following is not a keyword in java?

A - static

B - Boolean

C - void

C - private

Answer : B

Explaination

Boolean is a class and is not a keyword.

Answer : A

Explaination

A class is a blue print from which individual objects are created. A class can contain fields and methods to describe the behavior of an object.

Q 4 - Primitive variables are stored on Stack.

A - True

B - False

Answer : A

Explaination

Primitive variables like int, float are stored on Stack.

Q 5 - Objects are stored on Stack.

A - True

B - False

Answer : B

Explaination

Objects are allocated memory in heap memory space.

Q 6 - Static functions can be accessed using null reference.

A - True

B - False

Answer : A

Explaination

True, Static functions can be accessed via class name or via null reference.

Q 7 - Can we compare int variable with a boolean variable?

A - True

B - False

Answer : B

Explaination

True, Compile time error will occur if an int variable is compared with Boolean variable.

Q 8 - What of the following is the default value of a local variable?

A - null

B - 0

C - Depends upon the type of variable

D - Not assigned

Answer : D

Explaination

Local variables are not assigned any value by default.

Q 9 - What of the following is the default value of an instance variable?

A - null

B - 0

C - Depends upon the type of variable

D - Not assigned

Answer : C

Explaination

Instance variables are assigned default values based on their types. For example, int variable is assigned 0 and an object type variable is assigned null as default value.

Q 10 - What is the size of byte variable?

A - 8 bit

B - 16 bit

C - 32 bit

D - 64 bit

Answer : A

Explaination

The byte data type is represented by an 8-bit signed two's complement integer.

Minimum value: -128

Maximum value: 127

Q 11 - What is the size of short variable?

A - 8 bit

B - 16 bit

C - 32 bit

D - 64 bit

Answer : B

Explaination

The short data type is represented by 16-bit signed two's complement integer.

Minimum value: -32,768

Maximum value: 32,767

Q 12 - What is the size of int variable?

A - 8 bit

B - 16 bit

C - 32 bit

D - 64 bit

Answer : C

Explaination

The int data type is represented by 32-bit signed two's complement integer,

Minimum value: -231

Maximum value: 231-1

Q 13 - What is the size of long variable?

A - 8 bit

B - 16 bit

C - 32 bit

D - 64 bit

Answer : D

Explaination

The long data type is represented by 64-bit two's complement integer.

Minimum value: -263

Maximum value: 263-1

Q 14 - What is the size of float variable?

A - 8 bit

B - 16 bit

C - 32 bit

D - 64 bit

Answer : C

Explaination

The float data type is represented by single-precision 32-bit IEEE 754 floating point.

Q 15 - What is the size of double variable?

A - 8 bit

B - 16 bit

C - 32 bit

D - 64 bit

Answer : D

Explaination

The double data type is represented by double-precision 64-bit IEEE 754 floating point.

Q 16 - What is the size of char variable?

A - 8 bit

B - 16 bit

C - 32 bit

D - 64 bit

Answer : B

Explaination

The char data type is represented by single 16-bit Unicode character.

Minimum value: '\u0000' (or 0)

Maximum value: '\uffff' (or 65,535)

Q 17 - What is the size of boolean variable?

A - 8 bit

B - 16 bit

C - 32 bit

D - not precisely defined

Answer : B

Explaination

The boolean data type can take either true or false, but its "size" isn't precisely defined.

Q 18 - Is an empty .java file a valid source file?

A - True

B - False

Answer : A

Explaination

True, an empty .java file is a valid source file.

Q 19 - Can we have multiple classes in same java file?

A - True

B - False

Answer : A

Explaination

True, a java file can contain one public class and many other non-public classes.

Q 20 - Can we have two public classes in one java file?

A - True

B - False

Answer : B

Explaination

No, a java file can contain only one public class.

Q 21 - What is the default value of byte variable?

A - 0

B - 0.0

B - null

B - undefined

Answer : A

Explianation

Byte variable has default value of 0 if defined as an instance/static variable.

Q 22 - What is the default value of short variable?

A - 0.0

B - 0

B - null

B - undefined

Answer : B

Explaination

Short variable has default value of 0 if defined as an instance/static variable.

Q 23 - What is the default value of byte variable?

A - 0

B - 0.0

C - null

D - not defined

Answer : A

Explaination

Byte variable has default value of 0 if defined as an instance/static variable.

Q 24 - What is the default value of short variable?

A - 0.0

B - 0

C - null

D - not defined

Answer : B

Explaination

short variable has default value of 0 if defined as an instance/static variable.

Q 25 - What is the default value of int variable?

A - 0

B - 0.0

C - null

D - not defined

Answer : A

Explaination

int variable has default value of 0 if defined as an instance/static variable.

Answer Sheet

Question Number Answer Key
1 C
2 B
3 A
4 A
5 B
6 B
7 B
8 D
9 C
10 A
11 B
12 C
13 D
14 C
15 D
16 B
17 B
18 A
19 A
20 B
21 A
22 A
23 A
24 B
25 A
java_questions_answers.htm
Advertisements