Quiz 7

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 6

1.

The basic unit of encapsulation in Java is the: Mark for Review


(1) Points
method
package
classpath
class (*)

Incorrect

Incorrect. Refer to Section 7 Lesson 1.


2.

Consider

public class YourClass{


public YourClass(int i)
{/*code*/}
// more code...}
To instantiate YourClass, what would you write? Mark for Review
(1) Points
YourClass y = new YourClass();
YourClass y = new YourClass(3); (*)
YourClass y = YourClass(3);
YourClass y = YourClass();
None of the above.

Correct

Correct
3.

Which of the following calls the method calculate correc

tly?
Mark for Review
(1) Points
ThisClass t=new ThisClass(); int x=t.calculate(3,4); (*)

ThisClass t=new ThisClass(); int x=t.calculate(3);


int x=calculate(3,4);
ThisClass t=new ThisClass(); int x=t.calculate();

Correct

Correct

4.
A team is working on a coding project. They desire that
all portions of their code should have access to the classes that they write. Wh
at access modifier should be used for each class?
Mark for Review
(1) Points
public (*)
protected
private
default
All of the above

Incorrect

Incorrect. Refer to Section 7 Lesson 2.


5.

How is it possible for overloading to work?

Mark fo

r Review
(1) Points
There is no such thing as overloading.
The code has to be declared as private.
Java Virtual Machine searches until it finds a constructor name and argu
ment type match. (*)
The interpreter doesn't care what you name your constructors.

Incorrect

Incorrect. Refer to Section 7 Lesson 2.

Page 1 of 3
6.

Next

Summary

Which of the following can be used as a parameter?

Mark for Review

(1) Points
(Choose all correct answers)
Objects (*)
Constructors
Strings (*)
Integers (*)
Arrays (*)

Incorrect

Incorrect. Refer to Section 7 Lesson 2.


7.

Would this code be correct if a Dog is a HousePet? Why o

r Why not?
HousePet Scooby = new Dog();
(1) Points

Mark for Review

Maybe. There is no way to tell without seeing the methods for Dog and th
e methods for HousePet.
No, because ref must be declared either a HousePet or a Dog, but not bot
h.
Yes, because it is an abstract class.
Yes, because polymorphism allows this since Dog is a subclass of HousePe
t. (*)

Correct

Correct

8.
Mark for Review
(1) Points

Identify the correct way to declare an abstract class.

abstract public class ClassName{...}


public class abstract ClassName(...)
public abstract ClassName(...)
public abstract class ClassName{...} (*)

Incorrect

Incorrect. Refer to Section 7 Lesson 5.

9.
Abstract classes cannot implement interfaces. True or fa
lse?
Mark for Review
(1) Points
True
False (*)

Incorrect

Incorrect. Refer to Section 7 Lesson 5.

10.
Consider creating a class Square that extends the Rectan
gle class provided below. Knowing that a square always has the same width and le
ngth, which of the following best represents a constructor for the Square class?

Mark for Review


(1) Points

(*)
None of the above.

Correct

Correct

Previous

Page 2 of 3

Next

Summary

Review your answers, feedback, and question scores below. An asterisk (*) indica
tes a correct answer.
Section 7 Quiz
(Answer all questions in this section)
11.
Methods are generally declared as public so other classe
s may use them. True or false? Mark for Review
(1) Points
True (*)
False

Correct

Correct
12.

What is the Java Applet?

Mark for Review

(1) Points
(Choose all correct answers)
There is no such thing as a Java Applet.
It is the virtual machine that translates Java code into a representatio
n that the computer can understand.
A web-based Java program that is embedded into a web browser. (*)
A graphic visual included in Java. (*)

Incorrect

Incorrect. Refer to Section 7 Lesson 4.

13.
Static classes can exist as inner classes. True or false
?
Mark for Review
(1) Points
True (*)
False

Correct

Correct

14.
Static classes can't return instances of the parent clas
s when the parent class uses a private constructor. True or false?
Mark fo
r Review
(1) Points
True
False (*)

Incorrect

ue or false?
(1) Points

Incorrect. Refer to Section 7 Lesson 3.


15.
You can create static classes as independent classes. Tr
Mark for Review

True
False (*)

Incorrect
Previous

Incorrect. Refer to Section 7 Lesson 3.


Page 3 of 3

Summary

You might also like