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

Advanced Java

Java Miscellaneous

Java APIs & Frameworks

Java Useful Resources

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 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 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.

Q 4 - What is the default value of Boolean variable?

A - true

B - false

C - null

D - not defined

Answer : B

Explaination

boolean variable has default value of false if defined as an instance/static variable.

Answer : C

Explaination

It refers to the ability to make a class abstract in OOP. It helps to reduce the complexity and also improves the maintainability of the system.

Q 6 - Composition represents

A - HAS-A relationship.

B - IS-A relationship.

Answer : A

Explaination

Holding the reference of the other class within some other class is known as composition. It represents a HAS-A relationship. For example, a Student has a Pen. Here Student class has Pen as its instance variable.

Answer : A

Explaination

Method Overloading is example of static binding.

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