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

Answer : C

Explaination

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

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 String variable?

A - ""

B - ''

C - null

D - not defined

Answer : C

Explaination

String variable has default value of null if defined as an instance/static variable.

Answer : C

Explaination

By default, variables, methods and constructors can be accessed by any class lying in the same package.

Answer : C

Explaination

It is the technique of making the fields in a class private and providing access to the fields via public methods. If a field is declared private, it cannot be accessed by anyone outside the class, thereby hiding the fields within the class. Therefore encapsulation is also referred to as data hiding.

Q 6 - Can be constructor be made private?

A - True.

B - False.

Answer : A

Explaination

Yes, class with private constructor can not instantiated using new keyword.

Answer : A

Explaination

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

Answer : B

Explaination

A transient variable is a variable that may not be serialized during Serialization and which is initialized by its default value during de-serialization.

Answer : A

Explaination

The garbage collector invokes an object's finalize() method when it detects that the object has become unreachable.

java_questions_answers.htm
Advertisements