Quiz
Review today's material by taking this three-question quiz.
Questions
-
What operator do you use to call an object's constructor method and create a new object?
-
+
-
new
-
instanceof
-
What kinds of methods apply to all objects of a class rather than an individual object?
-
Universal methods
-
Instance methods
-
Class methods
-
If you have a program with objects named obj1 and obj2, what happens when you use the statement obj2 = obj1?
-
The instance variables in obj2 are given the same values as obj1.
-
obj2 and obj1 are considered to be the same object.
-
Neither a. nor b.
Answers
b.
c.
b. The = operator does not copy values from one object to another. Instead, it makes both variables refer to the same object.
Certification Practice
The following question is the kind of thing you could expect to be asked on a Java programming certification test. Answer it without looking at today's material.
Given:
public class AyeAye { int i = 40; int j; public AyeAye() { setValue(i++); } void setValue(int inputValue) { int i = 20; j = i + 1; System.out.println("j = " + j); } }
What is the value of the j variable at the time it is displayed inside the setValue() method?
-
a. 42
-
b. 40
-
c. 21
-
d. 20
The answer is available on the book's Web site at http://www.java21days.com. Visit the Day 3 page and click the Certification Practice link.