Java Mock Test


Advertisements

This section presents you various set of Mock Tests related to Java Framework. You can download these sample mock tests at your local machine and solve offline at your convenience. Every mock test is supplied with a mock test key to let you verify the final score and grade yourself.

Questions and Answers

Java Mock Test IV

Answer : B

Explaination

Serialization is the process of writing the state of an object to a byte stream.

Answer : A

Explaination

Deserialization is the process of restoring state of an object from a byte stream.

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

Synchronization is the capability to control the access of multiple threads to shared resources. synchronized keyword in java provides locking which ensures mutual exclusive access of shared resource and prevent data race.

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

Answer : A

Explaination

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

Q 7 - Which arithmetic operations can result in the throwing of an ArithmeticException?

A - / , %

B - * , +

C - ! , -

D - >>, <<

Answer : A

Explaination

Integer / and % can result in the throwing of an ArithmeticException.

Q 8 - Can try statements be nested?

A - True.

B - False.

Answer : A

Explaination

Yes, try statements be nested.

Answer : B

Explaination

Program throws "NoSuchMethodError" error at runtime.

Q 10 - 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 11 - 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.

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

Answer : A

Explaination

Runtime polymorphism or dynamic method dispatch is a process in which a call to an overridden method is resolved at runtime rather than at compile-time. In this process, an overridden method is called through the reference variable of a superclass.

Q 14 - Can constructor be inherited?

A - True.

B - False.

Answer : B

Explaination

No, constructor cannot be inherited.

Q 15 - Deletion is faster in LinkedList than ArrayList.

A - True.

B - False.

Answer : A

Explaination

Deletion in linked list is fast because it involves only updating the next pointer in the node before the deleted node and updating the previous pointer in the node after the deleted node.

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

Q 19 - Which of the following is a marker interface?

A - serializable

B - comparable

C - cloneable

D - none of the above.

Answer : A

Explaination

serializable is a marker interface.

Q 20 - Which of the following is a thread safe?

A - StringBuilder

B - StringBuffer

C - Both of the above

D - none of the above

Answer : B

Explaination

StringBuffer is thread safe.

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

Q 22 - which operator is considered to be with highest precedence?

A - () , []

B - =

C - ?:

D - %

Answer : A

Explaination

Postfix operators i.e () [] . is at the highest precedence.

Q 23 - This is the parent of Error and Exception classes.

A - Throwable

B - Catchable

C - MainError

D - MainException

Answer : A

Explaination

Throwable is the parent of both Error and Exception class.

Answer : B

Explaination

A program is expected to recover if an exception occurs.

Answer Sheet

Question Number Answer Key
1 B
2 A
3 B
4 A
5 B
6 A
7 A
8 A
9 B
10 B
11 B
12 B
13 A
14 B
15 A
16 A
17 D
18 A
19 A
20 B
21 A
22 A
23 A
24 A
25 B
java_questions_answers.htm
Advertisements