| Author |
why would this code run without an error?
|
sura watthana
Ranch Hand
Joined: Sep 13, 2004
Posts: 77
|
|
I don't understand why the code below would run without error since object orbiting has not been instantiated in the class Planet? public interface HeavenlyBody { String describe(); } class Star implements HeavenlyBody { String starName; public String describe() { return "star " + starName; } } class Planet { String name; Star orbiting; public String describe() { return "planet " + name + " orbiting " + orbiting.describe(); } }
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24054
|
|
|
It's not a complete program, as there's no "main" routine. The program could certainly run without error if no one called Planet.describe().
|
[Jess in Action][AskingGoodQuestions]
|
 |
 |
|
|
subject: why would this code run without an error?
|
|
|