fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. Ideone ideone = new Ideone();
  13. Ideone outro = new Ideone();
  14.  
  15. if (ideone.equals(outro)){ // comparando o objeto com ele mesmo
  16. System.out.println("É igual");
  17. }else{
  18. System.out.println("Não é igual");
  19. }
  20.  
  21. if (ideone.equals(ideone)){ // comparando o objeto com ele mesmo
  22. System.out.println("É igual");
  23. }else{
  24. System.out.println("Não é igual");
  25. }
  26. }
  27.  
  28. @Override
  29. public boolean equals(Object obj){
  30. if (this == obj)
  31. return true;
  32.  
  33. if (obj == null)
  34. return false;
  35.  
  36. if (getClass() != obj.getClass())
  37. return false;
  38.  
  39. return false;
  40. }
  41. }
Success #stdin #stdout 0.04s 2184192KB
stdin
Standard input is empty
stdout
Não é igual
É igual