Review Questions

6.27 Given the following code, which statements are true?
public interface HeavenlyBody { String describe(); }

class Star {
    String starName;
    public String describe() { return "star " + starName; }
}

class Planet extends Star {
    String name;
    public String describe() {
        return "planet " + name + " orbiting star " + starName;
    }
}

Select the two correct answers:

  1. The code will fail to compile.

  2. The use of inheritance is justified, since Planet is-a Star.

  3. The code will fail to compile if the name starName is replaced with the name bodyName throughout the declaration of the Star class.

  4. The code will fail to compile if the name starName is ...

Get Programmer's Guide to Java™ Certification, A: A Comprehensive Primer, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.