/* --- CSU213 Fall 2006 Lecture Notes --------- Copyright 2006 Viera K. Proulx Lecture 14: October 5, 2006 Overloading Constructors: Providing default options to the user */ class Book{ String title; int year; Book(String title, int year){ this.title = title; this.year = year; } // if the year is not given, assume this year Book(String title){ this(title, 2006); } // was this book published before the given year? boolean before(int year){ return this.year < year; } String asString(){ return new String("class Book " + "\n" + "title " + title + "\n" + "year " + year + "\n"); } } class Examples { Examples(){} Book book1 = new Book("DVC", 2002); Book book2 = new Book("Beach", 1999); Book book3 = new Book("HtDC"); String book1string = book1.asString(); String book2string = book2.asString(); String book3string = book3.asString(); // test the method before in the class Book boolean testBefore = (check book1.before(2000) expect false) && (check book2.before(2000) expect true) && (check book3.before(2000) expect false); }