The following code is from Bates and Sierra:
public class Book {
private String title; // instance reference variable
public String getTitle() {
return title;
}
public static void main(String [] args) {
Book b = new Book();
String s = b.getTitle(); // Compiles and runs
String t = s.toLowerCase(); // Runtime Exception!
}
}
Why does String t = s.toLowerCase()
cause a runtime exception when String s = b.getTitle()
does not?