Home / Java Programming / Java.lang Class :: Finding the output

Java Programming :: Java.lang Class

  1. What will be the output of the program?

    try  {     Float f1 = new Float("3.0");     int x = f1.intValue();     byte b = f1.byteValue();     double d = f1.doubleValue();     System.out.println(x + b + d); } catch (NumberFormatException e) /* Line 9 */ {     System.out.println("bad number"); /* Line 11 */ } 

  2. A.
    9.0
    B.
    bad number
    C.
    Compilation fails on line 9.
    D.
    Compilation fails on line 11.

  3. What will be the output of the program?

    class Q207  {      public static void main(String[] args)      {         int i1 = 5;          int i2 = 6;          String s1 = "7";          System.out.println(i1 + i2 + s1); /* Line 8 */     }  } 

  4. A.
    18
    B.
    117
    C.
    567
    D.
    Compiler error

  5. What will be the output of the program?

    public class SqrtExample  {     public static void main(String [] args)      {         double value = -9.0;         System.out.println( Math.sqrt(value));     } } 

  6. A.
    3.0
    B.
    -3.0
    C.
    NaN
    D.
    Compilation fails.

  7. What will be the output of the program?

    String s = "ABC";  s.toLowerCase();  s += "def";  System.out.println(s); 

  8. A.
    ABC
    B.
    abc
    C.
    ABCdef
    D.
    Compile Error

  9. What will be the output of the program?

    public class NFE  {     public static void main(String [] args)      {     String s = "42";         try          {             s = s.concat(".5");  /* Line 8 */             double d = Double.parseDouble(s);             s = Double.toString(d);             int x = (int) Math.ceil(Double.valueOf(s).doubleValue());             System.out.println(x);         }         catch (NumberFormatException e)          {             System.out.println("bad number");         }     } } 

  10. A.
    42
    B.
    42.5
    C.
    43
    D.
    bad number

  11. What will be the output of the program?

    System.out.println(Math.sqrt(-4D));

  12. A.
    -2
    B.
    NaN
    C.
    Compile Error
    D.
    Runtime Exception

  13. What will be the output of the program?

    interface Foo141  {      int k = 0; /* Line 3 */ }  public class Test141 implements Foo141  {     public static void main(String args[])      {         int i;          Test141 test141 = new Test141();          i = test141.k; /* Line 11 */         i = Test141.k;          i = Foo141.k;      }  } 

  14. A.
    Compilation fails.
    B.
    Compiles and runs ok.
    C.
    Compiles but throws an Exception at runtime.
    D.
    Compiles but throws a RuntimeException at runtime.

  15. What will be the output of the program?

    String a = "newspaper"; a = a.substring(5,7); char b = a.charAt(1); a = a + b; System.out.println(a); 

  16. A.
    apa
    B.
    app
    C.
    apea
    D.
    apep

  17. What will be the output of the program?

    public class StringRef  {     public static void main(String [] args)      {         String s1 = "abc";         String s2 = "def";         String s3 = s2;   /* Line 7 */         s2 = "ghi";         System.out.println(s1 + s2 + s3);     } } 

  18. A.
    abcdefghi
    B.
    abcdefdef
    C.
    abcghidef
    D.
    abcghighi

  19. What will be the output of the program?

    public class Test138  {      public static void stringReplace (String text)      {         text = text.replace ('j' , 'c'); /* Line 5 */     }      public static void bufferReplace (StringBuffer text)      {          text = text.append ("c");  /* Line 9 */     }      public static void main (String args[])      {          String textString = new String ("java");          StringBuffer textBuffer = new StringBuffer ("java"); /* Line 14 */         stringReplace(textString);          bufferReplace(textBuffer);          System.out.println (textString + textBuffer);      }  } 

  20. A.
    java
    B.
    javac
    C.
    javajavac
    D.
    Compile error