Java Online Quiz


Advertisements


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

A - 0

B - 0.0

C - 0L

D - not defined

Answer : C

Explaination

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

Answer : C

Explaination

Protected access modifier is used to restrict access to variables, methods and constructors to subclass only. Subclass can lie in different package.

Q 5 - Inheritance represents

A - HAS-A relationship.

B - IS-A relationship.

Answer : B

Explaination

Inheritance represets IS-A relationship providing code reusablity . Consider the following statement: Circle is a Shape. Here Shape is super class and Circle is a child class extends the super class Shape.

Answer : C

Explaination

Set is a collection of element which cannot contain duplicate elements. The Set interface contains only methods inherited from Collection and adds the restriction that duplicate elements are prohibited.

Answer : A

Explaination

A NullPointerException is thrown when calling the instance method of a null object or modifying/accessing field of a null object.

Q 8 - Does garbage collection guarantee that a program will not run out of memory?

A - True.

B - False.

Answer : B

Explaination

Garbage collection does not guarantee that a program will not run out of memory. It is possible for programs to use up memory resources faster than they are garbage collected. It is also possible for programs to create objects that are not subject to garbage collection.

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

A - True.

B - False.

Answer : B

Explaination

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


java_questions_answers.htm

Advertisements