Section 1: Test: Creating Classes, Objects, and Methods: Quiz
Section 1: Test: Creating Classes, Objects, and Methods: Quiz
Section 1: Test: Creating Classes, Objects, and Methods: Quiz
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 1
(Answer all questions in this section)
1. Which of the following creates a class named Diver with one constructor, and 2 Mark for
instance variables maxDepth and certified?
Review
(1) Points
(*)
2. The basic unit of encapsulation in Java is the: Mark for
Review
(1) Points
class (*)
classpath
method
package
Review
(1) Points
Review
(1) Points
Review
(1) Points
instance variables
instance methods
constructors
comments
6. Which of the following creates a Object from the Animal class listed below? Mark for
Review
(1) Points
Animal dog=Animal(50,30);
Review
(1) Points
True
False (*)
8. Which of the following creates an object from the Car class listed below? Mark for
Review
(1) Points
Car c = new Car(3000, "Toyota"); (*)
Car c=Car();
Car c;
9. The following statement compiles and executes. What can you say for sure? Mark for
submarine.dive(depth);
Review
(1) Points
10Which of the following creates a method that compiles with no errors in the class? Mark for
.
Review
(1) Points
(*)
11What value will be returned when the setValue method is called? Mark for
.
Review
(1) Points
35
36
37 (*)
38
12The return value of a method can only be a primitive type and not an object. True Mark for
. or false?
Review
(1) Points
True
False (*)
13Which of the following calls the method moveUp in the class below: Mark for
.
Review
(1) Points
14A class can have multiple constructors. True or false? Mark for
.
Review
(1) Points
True (*)
False
15The constructor of a class has the same name as the class. True or false? Mark for
.
Review
(1) Points
True (*)
False
16Complete the sentence. A constructor... Mark for
.
Review
(1) Points
17What operator do you use to call an object's constructor method and create a new Mark for
. object?
Review
(1) Points
new (*)
class
instanceOf
MyClass m = MyClass;
MyClass m = MyClass();
Review
(1) Points
The operating system periodically deletes all of the Java files available on the
system.
Any package imported in a program and not used is automatically deleted.
When all references to an object are gone, the memory used by the object is
automatically reclaimed. (*)
The JVM checks the output of any Java program and deletes anything that
does not make sense.
20Which of the following keywords are used to access the instance variables of an Mark for
. object from within the class code for that object?
Review
(1) Points
public
private
protected
this (*)
21Which of the following adds a constructor to the class below? Mark for
.
Review
(1) Points
(*)
22Which constructor code populates the instance variables of the class correctly? Mark for
.
Review
(1) Points
(*)