aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes why would this code run without an error? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "why would this code run without an error?" Watch "why would this code run without an error?" New topic
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: 24187
    
  34

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]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why would this code run without an error?