Advertisement
chrisenoch

== compares two different objects and returns true. Why?

Jan 12th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.61 KB | None | 0 0
  1. class GenMethDemo {
  2.     public static void main(String args[]) {
  3.         Test trial = new Test();
  4.         Test2 trial2 = new Test2();
  5.         Test trial3 = new Test();
  6.  
  7.         System.out.println(trial.a == trial.b);
  8.         System.out.println(trial.b == trial2.c); //Don't these point to different objects? Why is the result true?
  9.         System.out.println(trial.a == trial3.a); //Don't these point to different objects? Why is the result true?
  10.         System.out.println(trial.a);
  11.         System.out.println(trial.b);
  12.     }
  13. }
  14. class Test{
  15.     int a = 5;
  16.     int b = 5;
  17. }
  18. class Test2{
  19.     int c = 5;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement