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 II

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

Q 2 - What is the default value of float variable?

A - 0.0d

B - 0.0f

C - 0

D - not defined

Answer : B

Explaination

float variable has default value of 0.0f if defined as an instance/static variable.

Q 3 - What is the default value of double variable?

A - 0.0d

B - 0.0f

C - 0

D - not defined

Answer : A

Explaination

double variable has default value of 0.0d if defined as an instance/static variable.

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

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

Q 6 - What is the default value of Object variable?

A - undefined

B - 0

C - null

D - not defined

Answer : C

Explaination

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

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

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

Answer : C

Explaination

String is a object.

Answer : B

Explaination

String object is immutable so that once it is created a String object cannot be changed. Since String is immutable it can safely be shared between many threads which are considered very important for multithreaded programming.

Answer : B

Explaination

Polymorphism is the ability of an object to take on many forms. The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a child class object.

Answer : A

Explaination

It is the process where one object acquires the properties of another. With the use of inheritance the information is made manageable in a hierarchical order.

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.

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.

Answer : C

Explaination

An interface is a collection of abstract methods. A class implements an interface, thereby inheriting the abstract methods of the interface.

Answer : B

Explaination

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

Answer : A

Explaination

Variables defined inside methods, constructors or blocks are called local variables. The variable will be declared and initialized within the method and it will be destroyed when the method has completed.

Answer : C

Explaination

Instance variables are variables within a class but outside any method. These variables are instantiated when the class is loaded.

Answer : A

Explaination

Class variables are variables declared with in a class, outside any method, with the static keyword.

Q 24 - A class always has a default constructor.

A - True

B - False

Answer : B

Explaination

It is not mandatory to have a default constructor in a class.

Q 25 - 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 Sheet

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