Java Online Quiz


Following quiz provides Multiple Choice Questions (MCQs) related to Core Java. You will have to read all the given answers and click over the correct answer. If you are not sure about the answer then you can check the answer using Show Answer button. You can use Next Quiz button to check new set of questions in the quiz.

Questions and Answers

Q 1 - 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 2 - 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 3 - What is the default value of double variable?

A - 0.0d

B - 0.0f

C - 0

D - not defined

Answer : A

Explaination

double variable has default value of 0.0d if defined as an instance/static variable.

Answer : B

Explaination

String object is immutable so that once it is created a String object cannot be changed. Since String is immutable it can safely be shared between many threads which are considered very important for multithreaded programming.

Answer : B

Explaination

An immutable object can't be changed once it is created. String objects are immutable.

Answer : B

Explaination

A class consist of Local variable, instance variables and class variables.

Answer : A

Explaination

If a class has multiple functions by same name but different parameters, it is known as Method Overloading.

Answer : D

Explaination

A thread can enter the waiting state by invoking its sleep() method, by blocking on IO, by unsuccessfully attempting to acquire an object's lock, or by invoking an object's wait() method. It can also enter the waiting state by invoking its (deprecated) suspend() method.

Q 9 - Is it necessary that each try block must be followed by a finally block?

A - True.

B - False.

Answer : B

Explaination

It is not necessary that each try block must be followed by a finally block. It should be followed by either a catch block or a finally block.

Q 10 - Which method must be implemented by all threads?

A - wait()

B - start()

C - stop()

D - run()

Answer : D

Explaination

All threads must implement the run() method.

java_questions_answers.htm
Advertisements