Skip to content

Instantly share code, notes, and snippets.

@benfb
Created October 2, 2012 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benfb/3819925 to your computer and use it in GitHub Desktop.
Save benfb/3819925 to your computer and use it in GitHub Desktop.
BBaileyBookRunner
public class BBaileyBookRunner
{
public static void main(String args[])
{
BBaileyBook textBook = new Book(); //creates a new object textbook of class Book
textBook.setName("Scooby Doo"); //sets the name of textBook to "Scooby Doo"
textBook.getName(); //println would print default values if the default constructor was called. In this case, the output matches the input
System.out.println(textBook); //What does this line do? It calls the .toString() method
BBaileyBook theStranger = new Book("The Stranger", 123456789); //creates a new book with title "The Stranger" and ISBN 123...
System.out.println(textBook.getName); //prints textBook's name
theStranger.setName("Even Stranger"); //the method setName is used to change the name, and is a modifier method
theStranger.getName(); //does not print anything because there is no print statement in the method. getName is an accessor method
theStranger.setISBN(143412597); //changes theStranger's ISBN to 143412597
System.out.println(theStranger); //calls the toString method of theStranger object
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment