fork 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. Vector2d obj1 = new Vector2d(2,3);
  13. Vector2d obj2 = null;
  14.  
  15. System.out.println(obj1.equals(obj2));
  16. }
  17.  
  18. private static class Vector2d {
  19. int x;
  20. int y;
  21.  
  22. public Vector2d(int x, int y) {
  23. this.x = x;
  24. this.y = y;
  25. }
  26.  
  27. @Override
  28. public boolean equals(Object other){
  29. if (!(other instanceof Vector2d)){
  30. return false;
  31. } else {
  32. return equals((Vector2d) other);
  33. }
  34. }
  35.  
  36. public boolean equals(Vector2d other){
  37. return this.x == other.x && this.y == other.y;
  38. }
  39. }
  40.  
  41. }
Runtime error #stdin #stdout #stderr 0.08s 47128KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Exception in thread "main" java.lang.NullPointerException
	at Ideone$Vector2d.equals(Main.java:37)
	at Ideone.main(Main.java:15)