Given the following code, which statement is true?.
public interface Printable { String describe(); } class Star implements Printable { String starName;//from w ww . j a va 2 s . c o m public String describe() { return "star " + starName; } } class Main { String name; Star orbiting; public String describe() { return "planet " + name + " orbiting " + orbiting.describe(); } }
Select the one correct answer:.
starName
is replaced with the name bodyName
throughout the declaration of the Star class.starName
is replaced with the name name throughout the declaration of the Star class.(b)
The code will compile.
The code will not fail to compile if the name of the field starName
is changed in the Star class, since the Main class does not try to access the field by name, but instead uses the public method describe()
in the Star class for that purpose.
An instance of Main is not an instance of Printable, since it neither implements Printable nor extends a class that implements Printable.