Questions# 121-140



Question 121)

         Read this piece of code carefully

if("String".toString() == "String")
    System.out.println("Equal");
else
    System.out.println("Not Equal");


Answers
 

  1. the code will compile an print "Equal".
  2. the code will compile an print "Not Equal".
  3. the code will cause a compiler error.

Question 122)

         Read this piece of code carefully
 

if(" String ".trim() == "String")
    System.out.println("Equal");
else
    System.out.println("Not Equal");


Answers

  1. the code will compile an print "Equal".
  2. the code will compile an print "Not Equal".
  3. the code will cause a compiler error

Question 123)

Read the code below. Will be the result of attempting to compile and run the code below.
 

public class AQuestion
{
     public void method(Object o)
     {
         System.out.println("Object Verion");
     }
 public void method(String s)
 {
    System.out.println("String Version");
 }
 public static void main(String args[])
 {
     AQuestion question = new AQuestion();
     question.method(null);
 }
}
Answers
  1. The code does not compile.
  2. The code compiles cleanly and shows "Object Version".
  3. The code compiles cleanly and shows "String Version"
  4. The code throws an Exception at Runtime.



Question 124)

Read the code below. Will be the result of attempting to compile and run the code below.
 

public class AQuestion
{
     public void method(StringBuffer sb)
     {
         System.out.println("StringBuffer Verion");
     }
 public void method(String s)
 {
    System.out.println("String Version");
 }
 public static void main(String args[])
 {
     AQuestion question = new AQuestion();
     question.method(null);
 }
}
Answers
  1. The code does not compile.
  2. The code compiles cleanly and shows "StringBuffer Version".
  3. The code compiles cleanly and shows "String Version"
  4. The code throws an Exception at Runtime.

Question 125)

    Read the following code below.

    public interface AQuestion
    {
         public abstract void someMethod() throws Exception;
    }

    A Class implementing this interface should
     

  1. Necessarily be an abstract class.
  2. Should have the method public abstract void someMethod();
  3. Should have the method public void someMethod() which has to throw an exception which is a subclass of java.lang.Exception.
  4. Should have the method public void someMethod() which need not throw an Exception.

Question 126)

        An Interface can never be private or protected.

Answers

        True
        False


Question 127)

      A Vector class in jdk 1.2

  1. is public
  2. is final
  3. implements java.util.List
  4. is serializable
  5. has only One constructor



Question 128)

     A String Class

  1. is final
  2. is public
  3. is serializable
  4. has a constructor which takes a StingBuffer Object as an Argument



Question 129)

    public interface AQuestion
    {
         void someMethod();
    }
    The class which implements AQuestion
  1. Should have someMethod which must necessarily be public.
  2. Should have someMethod which could be "friendly" or public
  3. Should have someMethod which should not throw any checked exceptions.
  4. Should have someMethod which cannot be sychronized as sychronized is not in the signature of the interface defination



Question 130)

public class AQuestion
{
 private int i = j;
 private int j = 10;
 public static void main(String args[])
 {
      System.out.println((new AQuestion()).i);
 }
}


Question 131)

    public class AQuestion
    {
         private int i = giveMeJ();
         private int j = 10;

         private int giveMeJ()
         {
              return j;
         }

         public static void main(String args[])
         {
              System.out.println((new AQuestion()).i);
         }
    }

Answers
 

  1. Compiler error complaining about access restriction of private variables of AQuestion.
  2. Compiler error complaining about forward referencing.
  3. No Compilation error - The output is 0;
  4. No Compilation error - The output is 10;



Question 132)

    public class AQuestion
    {
         public static void main(String args[])
         {
              System.out.println("Before Try");
              try
              {
              }
              catch(Throwable t)
              {
                   System.out.println("Inside Catch");
              }
              System.out.println("At the End");
         }
    }
 
 

  1. Compiler error complaining about the catch block, where no Throwable object can ever be thrown.
  2. Compiler error - Throwable Object can not be caught, only Exceptions must be caught.
  3. No compiler error. The lines "Before Try" and "At the end" are printed on the screen.



Question 133)

public class AQuestion
{
     public static void main(String args[])
     {
          System.out.println("Before Try");
          try
          {
          }
          catch(java.io.IOException t)
          {
               System.out.println("Inside Catch");
          }
          System.out.println("At the End");
      }
}
  1. Compiler error complaining about the catch block where no IOException object can ever be thrown.
  2. Compiler error - IOException not found. It must be imported in the first line of the code.
  3. No compiler error. The lines "Before Try" and "At the end" are printed on the screen.



Question 134)

        The class java.lang.Exception

           i.   Is public
           ii.  Extends Throwable
           iii. Implements Throwable
           iv.  Is serializable


Question 135)

         Read this piece of code carefully

if("String".trim() == "String".trim())
    System.out.println("Equal");
else
    System.out.println("Not Equal");


Answers

  1. the code will compile an print "Equal".
  2. the code will compile an print "Not Equal".
  3. the code will cause a compiler error

Question 136)

         Read this piece of code carefully
 

if( "STRING".toUpperCase() == "STRING")
    System.out.println("Equal");
else
    System.out.println("Not Equal");


Answers

  1. the code will compile an print "Equal".
  2. the code will compile an print "Not Equal".
  3. the code will cause a compiler error

Question 137)

        The following lines of code

             byte b = 0;
             b += 1;
 

  1. results in b having the value 1.
  2. causes a compiler error.
  3. will require a cast (byte) before 1.



Question 138)

        The following express

            char c = -1;
 

  1. will cause a compiler error as the range of character is between 0 and 2^16 - 1. Will request for an explicit cast.
  2. will not cause a compiler error and c will have the value -1;
  3. c will not represent any ascii character.
  4. c will still be a unicode character.




 

Question 139)

        Which of the following statements are true?
 

  1. A method can throw an Exception
  2. A method can return an Exception



Question 140)

        All the  wrapper classes (Integer, Boolean, Float, Short, Long, Double and Character)
 

  1. are public
  2. are serializable
  3. are immutatable
  4. extend java.lang.Number
  5. are final

Back   Answers   Next      Index   Home