Thursday, 19 February 2015

Tricky Examples

// Wrapper Demos

public class WrapperDemos {
public static void main(String[] args) {
       int x=12;
       Integer s=new Integer(x);
       System.out.println(s);
       if(s==x)
       {
              System.out.println("wrapper");
       }
}
}



public class WrapperDemos {
public static void main(String[] args) {
       int x=12;
       Integer s=new Integer(x);
       System.out.println(s);
      
       Integer num = new Integer(10);
       Integer num2 = new Integer("20");
        int k=num.reverse(num);
       System.out.println(num);
       System.out.println(" kvalue " + k);
       if(s==x)
       {
              System.out.println("wrapper");
       }
      
       Float f1 = new Float(10.2);
//     Float f2 = new Float(10.3f);
//     Float f3 = new Float("89.0");
//     Character character = new Character('c');
//     Double double1 = new Double(29.0f);
//     Double double2 = new Double("67.90");
//     Boolean boolean1 = new Boolean(true);
//     Boolean boolean2 = new Boolean("true");
//     System.out.println(boolean2);
//     Boolean boolean3 = new Boolean("nari");
//     System.out.println(boolean3);
}
}


// Trickey Examples

public class ExceptionQuestion {
       public static void main(String[] args) {

              method();

       }

       @SuppressWarnings("finally")
       private static int method() {

              try {
                     System.out.println("try");
                     int x = 4 / 0;
                     return 5;

              } catch (Exception exception) {
                     System.out.println("catch");

              } finally {
                     System.out.println("finally");
                     return 0;
              }

       }
}






public class  TrickyExample {
       public static void main(String[] args) {

              method();

       }

       @SuppressWarnings("finally")
       private static int method() {

              try {
                     System.out.println("try");
                     int x = 4 / 0;
                     return 5;

              } catch (ArrayIndexOutOfBoundsException exception) {
                     System.out.println("catch");

              } finally {
                     System.out.println("finally");
                     return 0;
              }

       }
}



public class  TrickyExample {
       public static void main(String[] args) {

              method();

       }

       @SuppressWarnings("finally")
       private static int method() {

              try {
                     System.out.println("try");
                     return 5;

              } catch (Exception exception) {
                     System.out.println("catch");

              } finally {
                     System.out.println("finally");
                     return 0;
              }

       }
}



public class  TrickyExample {
      
              int x = 4;

              public static void main(String[] args) {
                     new  TrickyExample().go1();
              }

              public void go1() {
                     int x;
                     // go2(++x);
              }

              public void go2(int y) {
                     int x = ++y;
                     System.out.println(x);
              }
       }



public class  TrickyExample {
       public static void method(Object obj) {
              System.out.println("Object");
       }

       public static void method(String str) {
              System.out.println("String");
       }

       public static void main(String[] args) {
              method(null);
       }

}


public class  TrickyExample {
       public static void method(Object obj) {
              System.out.println("Object");
       }

       public static void method(String str) {
              System.out.println("String");
       }
       /*public static void method(Integer integer) {
              System.out.println("Integer");
       }*/

       public static void main(String[] args) {
              method(null);
       }

}



public class  TrickyExample {
       public static void method(Object obj) {
              System.out.println("Object");
       }

       public static void method(Exception exp) {
              System.out.println("Exception");
       }

       public static void method(ArithmeticException exp) {
              System.out.println("ArithmeticException");
       }

       public static void main(String[] args) {
              method(null);
       }
}


public class  TrickyExample {
      

       public static void main(String[] args) {
              if (null == null) {
                     System.out.println("hey this is true????");
              }
       }
}



public class  TrickyExample {
      

       public static void main(String[] args) {
              if (null == null) {
                     short x = 0;
                     int y = 05;
                     int z = 06;
                     int a = 1234;
                     x += a;
                     System.out.println("" + y + z + x);
              }
       }
}



No comments:

Post a Comment