0% found this document useful (0 votes)
54 views

Course:: The Quiz Questions

The document provides a quiz with questions about Java programming concepts like classes, objects, constructors, access modifiers, and Strings. It asks the reader to identify which answers are true for code examples and definitions. The answers section then reveals which choices were correct for each question.

Uploaded by

Fuad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

Course:: The Quiz Questions

The document provides a quiz with questions about Java programming concepts like classes, objects, constructors, access modifiers, and Strings. It asks the reader to identify which answers are true for code examples and definitions. The answers section then reveals which choices were correct for each question.

Uploaded by

Fuad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Course: Easy-to-follow Java programming

The quiz questions


Answer the questions below to review what you have learned in Video 7. You will
find the right answers after the questions in the solution section.

1. What does the following code section create?

public class StopWatch {


int hour;
int minute;
int second;
}

StopWatch sw = new
StopWatch();

2. Which of the following is true for constructor? (Several answers may be


correct.)

Constructor is a method.

The name of the constructor equals to the name of the class.

The constructor is obliged to set the values of ALL the data members.

The constructor can be called even if no object is created.

A constructor is always called if an object is created.

The return type of constructor is void.

If you do not create a constructor, one is created by the compiler.

We can create more than one constructor.

There is always a no-parameter constructor in a class.

Duckademy IT courses – www.duckademy.com


3. What is true for this reference? (Several answers may be correct.)

You can distinguish between the data member and the parameter with
the same name.

If you refer to a data member you always have to use this reference.

This reference refers to the actual object.

4. Which access modifier belongs to which definition (private, protected,


public, package private, static, default)?
(You may not have to use all, and you might have to use some in more than
one place.)

Designates the members that are accessible only from inside


the class.

You can access these members from all the classes.

Rule of thumb: you use it for data members – by default.

It can be accessed from the same class, from a subclass and from
the same package.

You can access the members designated with this modifier from
classes in the same package.

This is the name if you do not specify anything.

Rule of thumb: methods have this access modifier – by default.

5. What is true for a String? (Several answers may be correct.)

It is a class.

It is no different than char arrays.

Behaves similarly to primitive types.

You can use + and += operators with them.

If you change the content of a string, it remains the same object.

Strings can be converted to ints by a simple assignment:


int a = “56”;

Duckademy IT courses – www.duckademy.com


----------------------------------------------------------------------------------------------------------------

The answers

1. What does the following code section create?

class public class StopWatch {


int hour;
int minute;
int second;
}

object StopWatch sw = new


StopWatch();

2. Which of the following is true for constructor? (Several answers may be


correct.)

X Constructor is a method.
X The name of the constructor equals to the name of the class.

The constructor is obliged to set the values of ALL the data members.

The constructor can be called even if no object is created.


X A constructor is always called if an object is created.

The return type of constructor is void.


X If you do not create a constructor, one is created by the compiler.
X We can create more than one constructor.

There is always a no-parameter constructor in a class.

3. What is true for this reference? (Several answers may be correct.)

X You can distinguish between the data member and the


parameter with the same name.

If you refer to a data member you always have to use this


reference.
X This reference refers to the actual object.

Duckademy IT courses – www.duckademy.com


4. Which access modifier belongs to which definition (private, protected,
public, package private, static, default)?
(You may not have to use all, and you might have to use some in more than
one place.)

private Designates the members that are accessible only from inside
the class.
public You can access these members from all the classes.
private Rule of thumb: you use it for data members – by default.
protected It can be accessed from the same class, from a subclass and from
the same package.
package You can access the members designated with this modifier from
private classes in the same package.
package This is the name if you do not specify anything.
private

public Rule of thumb: methods have this access modifier – by default.

5. What is true for a String? (Several answers may be correct.)

X It is a class.

It is no different than char arrays.


X Behaves similarly to primitive types.
X You can use + and += operators with them.

If you change the content of a string, it remains the same object.

Strings can be converted to ints by a simple assignment:


int a = “56”;

Duckademy IT courses – www.duckademy.com

You might also like