HenriAugusto

Java Strange Behaviour

Feb 17th, 2017
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.55 KB | None | 0 0
  1.     public class HelloWorld
  2.     {
  3.       public static void main(String[] args)
  4.       {
  5.         Test test = new Test();
  6.         test.setA( test.a );
  7.        
  8.         if( test.a==null){
  9.           System.out.println("a is null ");
  10.         } else {
  11.           System.out.println("a is not null ");
  12.         }
  13.        
  14.       }
  15.     }
  16.    
  17.     public class A{
  18.     }
  19.    
  20.     public class Test{
  21.       A a; //use this and a is null
  22.       //A a = new A(); //use this and a is not null
  23.    
  24.       void setA(A a){
  25.         a = new A();
  26.       }
  27.      
  28.     }
Advertisement
Add Comment
Please, Sign In to add comment