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

Java Programming :: Java.lang Class

  1. What will be the output of the program?

    class Tree { }  class Pine extends Tree { }  class Oak extends Tree { }  public class Forest1  {      public static void main (String [] args)     {          Tree tree = new Pine();          if( tree instanceof Pine )              System.out.println ("Pine");          else if( tree instanceof Tree )              System.out.println ("Tree");          else if( tree instanceof Oak )              System.out.println ( "Oak" );          else              System.out.println ("Oops ");      }  } 

  2. A.
    Pine
    B.
    Tree
    C.
    Forest
    D.
    Oops

    View Answer

    Workspace

    Discuss Discuss in Forum


  3. What will be the output of the program?

    String d = "bookkeeper"; d.substring(1,7); d = "w" + d; d.append("woo");  /* Line 4 */ System.out.println(d); 

  4. A.
    wookkeewoo
    B.
    wbookkeeper
    C.
    wbookkeewoo
    D.
    Compilation fails.

    View Answer

    Workspace

    Discuss Discuss in Forum


  5. What will be the output of the program?

     String a = "ABCD";  String b = a.toLowerCase();  b.replace('a','d');  b.replace('b','c');  System.out.println(b); 

  6. A.
    abcd
    B.
    ABCD
    C.
    dccd
    D.
    dcba

    View Answer

    Workspace

    Discuss Discuss in Forum


  7. What will be the output of the program?

    public class ExamQuestion6  {     static int x;      boolean catch()     {         x++;          return true;      }      public static void main(String[] args)     {         x=0;          if ((catch() | catch()) || catch())              x++;          System.out.println(x);      }  } 

  8. A.
    1
    B.
    2
    C.
    3
    D.
    Compilation Fails

    View Answer

    Workspace

    Discuss Discuss in Forum


  9. What will be the output of the program?

    public class Test  {      public static void main(String[] args)      {         final StringBuffer a = new StringBuffer();          final StringBuffer b = new StringBuffer();           new Thread()          {              public void run()              {                 System.out.print(a.append("A"));                  synchronized(b)                  {                      System.out.print(b.append("B"));                  }              }          }.start();                       new Thread()          {             public void run()              {                 System.out.print(b.append("C"));                  synchronized(a)                  {                     System.out.print(a.append("D"));                  }              }          }.start();      }  } 

  10. A.
    ACCBAD
    B.
    ABBCAD
    C.
    CDDACB
    D.
    Indeterminate output

    View Answer

    Workspace

    Discuss Discuss in Forum


  11. What will be the output of the program?

    String s = "hello";  Object o = s;  if( o.equals(s) ) {     System.out.println("A");  }  else {     System.out.println("B");  }  if( s.equals(o) ) {     System.out.println("C");  }  else {      System.out.println("D");  } 
    1. A
    2. B
    3. C
    4. D

  12. A.
    1 and 3
    B.
    2 and 4
    C.
    3 and 4
    D.
    1 and 2

    View Answer

    Workspace

    Discuss Discuss in Forum


  13. What will be the output of the program (in jdk1.6 or above)?

    public class BoolTest  {     public static void main(String [] args)      {         Boolean b1 = new Boolean("false");         boolean b2;         b2 = b1.booleanValue();         if (!b2)          {             b2 = true;             System.out.print("x ");         }         if (b1 & b2) /* Line 13 */         {             System.out.print("y ");         }         System.out.println("z");     } } 

  14. A.
    z
    B.
    x z
    C.
    y z
    D.
    Compilation fails.

    View Answer

    Workspace

    Discuss Discuss in Forum