Advertisement
Andrei_M

ass3

Oct 9th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.53 KB | None | 0 0
  1. class Book
  2. {  
  3.  
  4.     private int pages;
  5.    
  6.     public Book(int n)
  7.     {
  8.         pages = n;
  9.     }
  10.     public void print()
  11.     {
  12.         System.out.println(pages + " pages");
  13.     }
  14.    
  15.     public boolean equals(Object o)
  16.     {
  17.         return (o instanceof Book) && (pages == ((Book)o).pages);
  18.     }
  19. }
  20.  
  21. class Main
  22. {
  23.     public static void main(String args[])
  24.     {
  25.         Book book1 = new Book(5);
  26.         Book book2 = new Book(5);
  27.         boolean x = book1.equals(book2);
  28.         System.out.println(x);
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement