wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Constructors_crt

Total questions: 15

Worksheet time: 10mins

Name
Class
Date
1.

What is the purpose of a constructor in Java?

a)

To destroy objects

b)

To initialize objects

c)

To display output

d)

To perform calculations

2.

A constructor has the same name as the ______.

a)

Package

b)

Method

c)

Class

d)

Variable

3.

Which type of constructor takes no parameters?

a)

Parameterized constructor

b)

Default constructor

c)

Copy constructor

d)

Static constructor

4.

Which constructor accepts arguments?

a)

Default constructor

b)

Empty constructor

c)

Final constructor

d)

Parameterized constructor

5.

How many constructors can a class contain?

a)

Only one

b)

Two

c)

Three

d)

Multiple Constructors

6.

Which keyword refers to the current object?

a)

super

b)

static

c)

this

d)

final

7.

Which constructor is automatically provided by Java when no constructor is defined?

a)

Default constructor

b)

Parameterized constructor

c)

Copy constructor

d)

Static constructor

8.

What will be the output?

class Test{

Test(){

System.out.println("Constructor");

}

public static void main(String args[]){

Test t = new Test();

}

}

a)

Error

b)

Constructor

c)

Test

d)

Output

9.

What is the output?

class Demo{

int x;

Demo(){

x = 50;

}

public static void main(String args[]){

Demo d = new Demo();

System.out.println(d.x);

}

}

a)

0

b)

10

c)

50

d)

Error

10.

What is the output?

class Student{

Student(){

System.out.println("Hello");

}

Student(int a){

System.out.println("Java");

}

public static void main(String args[]){

Student s = new Student(5);

}

}

a)

Hello

b)

Java

c)

Hello Java

d)

Hello

Hello

11.

What is the output?

class Demo{

Demo(){

this(10);

System.out.println("Default");

}

Demo(int a){

System.out.println("Parameterized");

}

public static void main(String args[]){

new Demo();

}

}

a)

Default Parameterized

b)

Parameterized Default

c)

Error

d)

No output

12.

constructor is automatically invoked when an ​ (a)   is created.

13.

class A{

A(){

System.out.println("Hello");

}

public static void main(String args[]){

A obj = ​ (a)   A();

}

}

14.

class Demo{

int x;

Demo(int x){

​ (a)   .x = x;

}

}

15.

A constructor having parameters is called a ​ (a)   constructor.