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

A - '\u0000'

B - 0

C - null

D - not defined

Answer : A

Explaination

char variable has default value of '\u0000' if defined as an instance/static variable.

Answer : B

Explaination

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

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

Method Overloading is example of static binding.

Answer : A

Explaination

These are classes that allow primitive types to be accessed as objects. Example: Integer, Character, Double, Boolean etc.

Q 9 - Can a top level class be private or protected?

A - True.

B - False.

Answer : B

Explaination

No, a top level class can not be private or protected. It can have either "public" or no modifier.

Q 10 - Which of the following is Faster, StringBuilder or StringBuffer?

A - StringBuilder

B - StringBuffer

C - Both of the above.

D - none of the above.

Answer : A

Explaination

StringBuilder is faster than StringBuffer.


java_questions_answers.htm

Advertisements