Home > Articles > Programming > Java

  • Print
  • + Share This
This chapter is from the book

Quiz

Review today's material by taking this quiz.

Questions

  1. What operator do you use to call an object's constructor method and create a new object?

    1. +

    2. new

    3. instanceof

  2. What kinds of methods apply to all objects of a class rather than an individual object?

    1. Universal methods

    2. Instance methods

    3. Class methods

  3. If you have a program with objects named obj1 and obj2, what happens when you use the statement obj2 = obj1?

    1. The instance variables in obj2 are given the same values as obj1.

    2. obj2 and obj1 are considered to be the same object.

    3. Neither (a.) nor (b.).

Answers

  1. b.

  2. c.

  3. 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?

  1. 42

  2. 40

  3. 21

  4. 20

The answer is available on this book's Web site at http://www.java21days.com. Visit the Day 3 page and click the Certification Practice link.

  • + Share This
  • 🔖 Save To Your Account