public class TestBook { /** * @param args */ public static void main(String[] args) { Book book1= new Book(); System.out.println("Plain book object: "+book1); book1.setAuthor("Isaac Asimov"); book1.setTitle("End of the Eternity"); book1.setPageCount(450); System.out.println("After setting book object: "+book1); Book book2= new Book("Isaac Asimov","End of the Eternity",450); // == returns true only when the variables refer to the same object // Here although the objects are identical == returns false because they are different objects if(book1==book2){ System.out.println("== opeator says the books are the same"); } else{ System.out.println("== opeator says the books are not the same"); } // You can define equals method to do arbitrary equality checking if(book1.equals(book2)){ System.out.println("equals() method says the books are the same"); } else{ System.out.println("equals() method says the books are not the same"); } Book book3 = book2; if(book3==book2){ System.out.println("book3 and book2 refer to the same object"); } else{ System.out.println("book3 and book2 don't refer to the same object"); } Book dune=new Book("Frank Herbert","Dune",350); dune.setCurrentPage(300); dune.turnPage(); dune.turnPage(); System.out.println(dune.getCurrentPage()); System.out.println(dune.getEstimatedTimeLeft()); // references and call by value. The modifications made to the object inside the method is also visible outside. System.out.println(dune); changeAuthor(dune); System.out.println(dune); // static variables are shared by all objects of the class. System.out.println(book1.description); System.out.println(book2.description); Book.description="Empty description"; System.out.println(book1.description); System.out.println(book2.description); } private static void changeAuthor(Book b){ b.setAuthor("Dr. Aronis"); } }