Advertisement
alexarcan

lab2.4

Oct 3rd, 2014
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. class Pages
  2. {
  3. private int pages;
  4.  
  5. public Pages()
  6. {
  7. pages = 0;
  8. }
  9.  
  10. public Pages(int p)
  11. {
  12. pages = p;
  13. }
  14.  
  15. public void print()
  16. {
  17. System.out.println("My nb of pages: " + pages);
  18. }
  19.  
  20. public String toString()
  21. {
  22. return "My nb of pages is " + pages;
  23. }
  24.  
  25. public boolean equals(Object o)
  26. {
  27. return (o instanceof Pages) && ((Pages)o).pages == pages;
  28. }
  29. }
  30. class PagesMain
  31. {
  32. public static void main(String[] args)
  33. {
  34. Pages p1 = new Pages(100);
  35. Pages p2 = new Pages(100);
  36.  
  37. System.out.println(p1);
  38. System.out.println(p2);
  39.  
  40. System.out.println(p1.equals(p2));
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement