Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

java1

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

What is the primary purpose of a constructor in Java?

a)

To define methods within a class.

b)

To create objects of a class

c)

To initialize the state (instance variables) of an object.

d)

To declare class attributes

2.

Which of the following statements about Java constructors is true?

a)

Constructors can have a return type, including void.

b)

Constructors are inherited by subclasses

c)

A class can have multiple constructors, provided they have different parameter lists (constructor overloading).

d)

Constructors must always be declared public

3.

What is the difference between a constructor and a method in Java?

a)

Constructors do not have a return type, while methods do.

b)

Methods are used to create objects, while constructors are not.

c)

Constructors can be called multiple times, while methods cannot.

d)

Methods are used to initialize instance variables, while constructors are not.

4.

Can a constructor be private in Java?

a)

No, private constructors are not allowed in Java.

b)

No, constructors must always be public.

c)

Yes, to restrict object creation from outside the class.

d)

Yes, but only if the class is abstract.

5.

What happens if a class does not explicitly define a constructor in Java?

a)

The class will not compile.

b)

A default constructor is provided by the compiler.

c)

Only static methods can be called.

d)

The class will throw an error at runtime.

6.

What is constructor overloading in Java?

a)

Defining multiple constructors with the same parameter list.

b)

Defining multiple constructors with different parameter lists.

c)

Using constructors in a subclass only.

d)

Creating a constructor that returns a value.

7.

Which of the following is true about the default constructor in Java?

a)

It initializes all instance variables to their default values.

b)

It must be declared as public.

c)

It can be defined by the user only.

d)

It cannot be used if a parameterized constructor is defined.

8.

What is the result of calling a constructor from another constructor in the same class?

a)

It can only be done with static methods.

b)

It will cause a compilation error.

c)

It is called constructor chaining.

d)

It is not allowed in Java.

9.

What happens if you do not define any constructor in a Java class?

a)

a) The program will not compile.

b)

The compiler automatically provides a default (no-argument) constructor.

c)

The class cannot be instantiated

d)

The constructor from another class will be used. 

10.

What is a constructor in Java?

a)

A method that returns a value

b)

A special type of method that is used to initialize objects

c)

A method to perform mathematical calculations

d)

A method that is used to print output