Dd2

45 Questions | Attempts: 800
Share

SettingsSettingsSettings
Dd2 - Quiz

Questions and Answers
  • 1. 

    Which of the following is the best-performing implementation of Set interface?

    • A.

      HashSet

    • B.

      TreeSet

    • C.

      Hashtable

    • D.

      LinkedHashSet

    • E.

      SortedSet

    Correct Answer
    A. HashSet
  • 2. 

    Consider the following code snippet:   public class Welcome { String title; int value;   public Welcome() { title += " Planet"; }   public void Welcome() { System.out.println(title + " " + value); }   public Welcome(int value) { this.value = value; title = "Welcome"; Welcome(); }   public static void main(String args[]) { Welcome t = new Welcome(5); } }   Which of the following option will be the output for the above code snippet?

    • A.

      Compilation fails

    • B.

      Welcome Planet 5

    • C.

      Welcome 5

    • D.

      Welcome Planet

    • E.

      The code runs with no output

    Correct Answer
    C. Welcome 5
  • 3. 

    Consider the following code:   class ExampleFive { public static void main(String[] args) { final int i = 22; byte b = i; System.out.println(i + ", " + b); } }   Which of the following gives the valid output for the above code?

    • A.

      Prints: 22, 20

    • B.

      Runtime Error: Cannot type cast int to byte

    • C.

      Prints: 22, 22

    • D.

      Compile Time Error: Loss of precision

    Correct Answer
    C. Prints: 22, 22
  • 4. 

    Consider the following code snippet:   abstract class Director { protected String name;   Director(String name) { this.name = name; } abstract void occupation(); }   class FilmDirector extends Director { FilmDirector(String name) { super(name); }   void occupation() { System.out.println("Director " + name + " directs films"); } }   public class TestDirector { public static void main(String[] args) { FilmDirector fd = new FilmDirector("Manirathnam"); fd.occupation(); new Director("Manirathnam") { void occupation() { System.out.println("Director " + name + " also produces films"); } }.occupation(); } }   Which of the following will be the output of the above code snippet?  

    • A.

      Prints: Director Manirathnam also produces films

    • B.

      Compilation fails at TestDirector class

    • C.

      Prints: Director Manirathnam directs films

    • D.

      Runtime Error

    • E.

      Prints: Director Manirathnam directs filmsDirector Manirathnam also produces films

    Correct Answer
    E. Prints: Director Manirathnam directs filmsDirector Manirathnam also produces films
  • 5. 

    Consider the following code snippet:   class TestString2 { public static void main(String args[]) { String s1 = "Test1"; String s2 = "Test2";   s1.concat(s2);   System.out.println(""+s1.charAt(s1.length() - 3) + s1.indexOf(s2)); } }   What will be the output of the above code snippet?

    • A.

      S5

    • B.

      S-1

    • C.

      T4

    • D.

      15

    • E.

      T4

    Correct Answer
    B. S-1
  • 6. 

    Consider the following code:   1. public class SwitchIt { 2. public static void main(String[] args) { 3. int w1 = 1; 4. int w2 = 2; 5. System.out.println(getW1W2(w1, w2)); 6. } 7. 8. public static int getW1W2(int x, int y) { 9. switch (x) { 10. case 1: x = x + y; 11. case 2: x = x + y; 12. }   13. return x; 14. } 15. } Which of the following gives the valid output of above code?

    • A.

      Compilation succeeds and the program prints "5"

    • B.

      Compilation fails because of an error on line 9

    • C.

      Compilation succeeds and the program prints "3"

    • D.

      Compilation fails because of errors on lines 10 and 11

    Correct Answer
    A. Compilation succeeds and the program prints "5"
  • 7. 

    Consider the following code snippet:   class Train { String name = "Shatapdhi"; }   class TestTrain { public static void main(String a[]) { Train t = new Train(); System.out.println(t); // Line a System.out.println(t.toString()); // Line b } }   Which of the following statements are true?(Choose 3)

    • A.

      Line a prints the corresponding classname with Object'shashcode in Hexadecimal

    • B.

      Both Line a and Line b prints "Shatapdhi"

    • C.

      Both Line a and Line b will print the corresponding classnamewith Object's hashcode in Hexa Decimal

    • D.

      Output of Line a and Line b will be different

    • E.

      Output of Line a and Line b will be same

    Correct Answer(s)
    A. Line a prints the corresponding classname with Object'shashcode in Hexadecimal
    C. Both Line a and Line b will print the corresponding classnamewith Object's hashcode in Hexa Decimal
    E. Output of Line a and Line b will be same
  • 8. 

    Which of the following is true about finalize() method?

    • A.

      The finalize() method is guaranteed to run once and onlyonce before the garbage collector deletes an object

    • B.

      Finalize() is called when an object becomes eligible forgarbage collection

    • C.

      An object can be uneligibilize for GC from within finalize()

    • D.

      Calling finalize() method will make the object eligible forGarbage Collection

    • E.

      Finalize() method can be overloaded

    Correct Answer
    A. The finalize() method is guaranteed to run once and onlyonce before the garbage collector deletes an object
  • 9. 

    Consider the following program:   class RE { public static void main(String args[]) { try { String s = null; System.out.println(s.length()); } catch(NullPointerException npe) { System.out.println("NullPointerException handled"); throw new Exception(npe.getMessage()); } } }   What will be the output of the above program?

    • A.

      Code compiles and on running creates and throws Exceptiontype object

    • B.

      Code compiles but run without any output

    • C.

      Code does not complile

    • D.

      Code compiles and on running it prints "NullPointerExceptionhandled" then creates and throws Exception type object

    Correct Answer
    C. Code does not complile
  • 10. 

    Which of the following options will protect the underlying collections from getting modified?

    • A.

      UnmodifiableCollection(Collection

    • B.

      Collections.checked

    • C.

      SynchronizedCollection(Collection c);

    • D.

      None of the listed options

    Correct Answer
    A. UnmodifiableCollection(Collection
  • 11. 

    Which of the following are correct regarding HashCode?(Choose 2)

    • A.

      The numeric key is unique

    • B.

      It improves performance

    • C.

      It is a 32 bit numeric digest key

    • D.

      HashCode() value cannot be a zero-value

    • E.

      HashCode() is defined in String class

    Correct Answer(s)
    B. It improves performance
    C. It is a 32 bit numeric digest key
  • 12. 

    Which of the following are true about inheritance?(Choose 3)

    • A.

      In an inheritance hierarchy, a subclass can also act as a superclass

    • B.

      Inheritance enables adding new features and functionality toan existing class without modifying the existing class

    • C.

      In an inheritance hierarchy, a superclass can also act as a subclass

    • D.

      Inheritance is a kind of Encapsulation

    • E.

      Inheritance does not allow sharing data and methods amongmultiple classes

    Correct Answer(s)
    A. In an inheritance hierarchy, a subclass can also act as a superclass
    B. Inheritance enables adding new features and functionality toan existing class without modifying the existing class
    C. In an inheritance hierarchy, a superclass can also act as a subclass
  • 13. 

    Consider the following program:   public class TryIt { public static void main(String args[]) { try { int i = 0; try { i = 100 / i; } catch(Error e) { System.out.println("Divide by Zero error"); } System.out.println("Error Handled"); } catch(Exception e) { System.out.println("Unexpected exception caught"); } } }   What will be the output of the above program?

    • A.

      Divide by Zero errorError HandledUnexpected exception caught

    • B.

      Program compiles and runs without any output

    • C.

      Divide by Zero errorError Handled

    • D.

      Unexpected exception caught

    • E.

      Error HandledUnexpected exception caught

    Correct Answer
    D. Unexpected exception caught
  • 14. 

    At which of the following given situations, unit tests are required to be run on the modules?(Choose 3)

    • A.

      When the modules are deployed to the server

    • B.

      When the other methods, referred in a method in a moduleis modified

    • C.

      When class members are modified

    • D.

      When a method in a module is completed or modified

    • E.

      When the modules are compiled

    Correct Answer(s)
    B. When the other methods, referred in a method in a moduleis modified
    C. When class members are modified
    D. When a method in a module is completed or modified
  • 15. 

    Consider the following code:   1 public class A { 2 public void m1() {System.out.print("A.m1, ");} 3 protected void m2() {System.out.print("A.m2, ");} 4 private void m3() {System.out.print("A.m3, ");} 5 void m4() {System.out.print("A.m4, ");} 6 7 public static void main(String[] args) { 8 A a = new A(); 9 a.m1(); 10 a.m2(); 11 a.m3(); 12 a.m4(); 13 } 14 }   Which of the following gives the lines that need to be removed in order to compile and run the above code correctly?

    • A.

      Lines 10, 11

    • B.

      No need to comment any line. Will compile and run

    • C.

      Lines 10, 11 and 12

    • D.

      Line 11

    Correct Answer
    B. No need to comment any line. Will compile and run
  • 16. 

    Which of the following options give the names of data structures that can be used for elements that have ordering, but no duplicates? (Choose 2)

    • A.

      ArrayList

    • B.

      List

    • C.

      TreeSet

    • D.

      Set

    • E.

      SortedSet

    Correct Answer(s)
    C. TreeSet
    E. SortedSet
  • 17. 

    Which of the following class in java.sql package maps the SQL data types to Java datatypes?

    • A.

      No explicit data type mapping. Automatically mapped onQuery Call.

    • B.

      JDBCTypes

    • C.

      Types

    • D.

      JDBCSQLTypes

    • E.

      SQLTypes

    Correct Answer
    C. Types
  • 18. 

    Which of the following options gives the difference between == operator and equals() method?

    • A.

      Equals compares hash value and == compares charactersequence

    • B.

      No difference;they are essentially the same

    • C.

      If equals() is true then == is also true

    • D.

      ==compares object's memory address but equals charactersequence

    • E.

      == works on numbers equals() works on characters

    Correct Answer
    D. ==compares object's memory address but equals charactersequence
  • 19. 

    Consider the following code:   package test;   class Target { String name = "hello"; }   Which of the following options are valid that can directly access and change the value of the variable 'name' in the above code? (Choose 2)

    • A.

      Any class

    • B.

      Any class that extends Target within the test package

    • C.

      Any class that extends Target outside the test package

    • D.

      Only the Target class

    • E.

      Any class in the test package

    Correct Answer(s)
    B. Any class that extends Target within the test package
    E. Any class in the test package
  • 20. 

    Which of the following are the valid ways of conversion from Wrapper type to primitive type? (Choose 3)

    • A.

      New Boolean("true").intValue();

    • B.

      New Double(24.5d).byteValue();

    • C.

      New Integer(1).booleanValue();

    • D.

      New Float(100).intValue();

    • E.

      New Integer(100).intValue();

    Correct Answer(s)
    B. New Double(24.5d).byteValue();
    D. New Float(100).intValue();
    E. New Integer(100).intValue();
  • 21. 

    Which of the following classes is new to JDK 1.6?

    • A.

      Java.io.File

    • B.

      Java.io.Serializable

    • C.

      Java.io.FileFilter

    • D.

      Java.io.Console

    • E.

      Java.io.Externalizable

    Correct Answer
    D. Java.io.Console
  • 22. 

    Which of the following statements are correct regarding Static Blocks?(Choose 3)

    • A.

      A class that have static block, should have the main() methoddefined in it

    • B.

      A class can have more than one static block

    • C.

      Static blocks are executed only once

    • D.

      Static blocks are executed before main() method

    • E.

      A static block can call other methods in a class

    Correct Answer(s)
    B. A class can have more than one static block
    C. Static blocks are executed only once
    D. Static blocks are executed before main() method
  • 23. 

    Which of the following ways can be used to access the String value in the first column of a ResultSet? (Assume rs is the ResultSet object)

    • A.

      Rs.getString(1);

    • B.

      Rs.getString("one");

    • C.

      None of listed options

    • D.

      Rs.getString("first");

    • E.

      Rs.getString(0);

    Correct Answer
    A. Rs.getString(1);
  • 24. 

    Which of the following options gives the relationship between a Spreadsheet Object and Cell Objects?

    • A.

      Polymorphism

    • B.

      Association

    • C.

      Aggregation

    • D.

      Inheritance

    • E.

      Persistence

    Correct Answer
    C. Aggregation
  • 25. 

    Consider the following program:   class A implements Runnable { public void run() { System.out.print(Thread.currentThread().getName()); } }   class B implements Runnable { public void run() { new A().run(); new Thread(new A(),"T2").run(); new Thread(new A(),"T3").start(); } }   class C { public static void main (String[] args) { new Thread(new B(),"T1").start(); } }   What will be the output of the above program?

    • A.

      Prints: T1T2T2

    • B.

      Prints: T1T2T3

    • C.

      Prints: T1T1T2

    • D.

      Prints: T1T1T1

    • E.

      Prints: T1T1T3

    Correct Answer
    E. Prints: T1T1T3
  • 26. 

    Consider the following program:   public class Exp4 { static String s = "smile!.."; public static void main(String[] args) { new Exp4().s1(); System.out.println(s); }   void s1() { try { s2();   } catch (Exception e) { s += "morning"; } }   void s2() throws Exception { s3(); s += "evening"; s3(); s += "good"; }   void s3() throws Exception { throw new Exception(); } }   What will be the output of the above program?

    • A.

      Smile!..eveningmorning

    • B.

      Smile!..morningevening

    • C.

      Smile!..morning

    • D.

      Smile!..morningeveninggood

    • E.

      Smile!..

    Correct Answer
    C. Smile!..morning
  • 27. 

    A monitor called 'mon' has 5 threads in its waiting pool; all these waiting threads have the same priority. One of the threads is thread1. How can you notify thread1 so that it alone moves from Waiting state to Ready State?

    • A.

      Execute mon.notify(thread1); from synchronized code of anyobject

    • B.

      Execute thread1.notify(); from any code(synchronized or not)of any object

    • C.

      Execute thread1.notify(); from synchronized code of anyobject

    • D.

      Execute notify(thread1); from within synchronized code ofmon

    • E.

      You cannot specify which thread will get notified

    Correct Answer
    E. You cannot specify which thread will get notified
  • 28. 

    Consider the following scenario:   Here is part of the hierarchy of exceptions that may be thrown during file IO operations:   Exception +-IOException +-File Not Found Exception   You have a method X that is supposed to open a file by name and read data from it. Given that X does not have any try-catch statements, which of the following option is true?

    • A.

      The method X must be declared as throwingFileNotFoundException

    • B.

      Any method calling X must use try-catch, specifically catchingFileNotFoundException

    • C.

      The method X must be declared as throwing IOException orException

    • D.

      No special precautions need be taken

    Correct Answer
    C. The method X must be declared as throwing IOException orException
  • 29. 

    The return value of execute() method in Statement interface is __________________.

    • A.

      Array of int

    • B.

      Boolean

    • C.

      ResultSet

    • D.

      Array of ResultSet

    • E.

      Int value

    Correct Answer
    B. Boolean
  • 30. 

    Consider the following program:   public class D extends Thread { public void run() { System.out.println("Before start method"); this.stop(); System.out.println("After stop method"); }   public static void main(String[] args) { D a = new D(); a.start(); } }   What will be the output of the above program?

    • A.

      'Before start method' and 'After stop method'

    • B.

      Compilation error

    • C.

      'Before start method' only

    • D.

      Runtime exception

    Correct Answer
    C. 'Before start method' only
  • 31. 

    Consider the following code:   public class Choco { Choco() { System.out.print("Choco"); }   class Bar { Bar() { System.out.print("bar"); } public void go() { System.out.print("sweet"); } }   public static void main(String[] args) { Choco c = new Choco(); c.makeBar(); } void makeBar(){ // Insert code here } }   Which of the following code snippet when substituted individually to the above commented line (// Insert code here) will give the following output?   Chocobarsweet

    • A.

      New Choco().go();

    • B.

      New Bar().go();

    • C.

      New Choco(). new Bar().go();

    • D.

      (new Bar() {}).go();

    • E.

      Go();

    Correct Answer
    D. (new Bar() {}).go();
  • 32. 

    Which of the following actions include the external library required by Java application at runtime in order to run properly? (choose 2)

    • A.

      Compressing the class into zip files and converting it intoexecutable modules, and then packaging it into a jar file

    • B.

      Adding the folder name or jar filename to the CLASSPATHvariable, where the class files of the library exists

    • C.

      Running the application with the following switchesjava -cp ApplicationClassNamejava -classpath ApplicationClassName

    • D.

      Cannot refer to an external libarary, it should be includedbefore the application is packaged.

    • E.

      Pointing the system's PATH variable to the folder or the jarfilename where the class files of the library exists

    Correct Answer(s)
    B. Adding the folder name or jar filename to the CLASSPATHvariable, where the class files of the library exists
    C. Running the application with the following switchesjava -cp ApplicationClassNamejava -classpath ApplicationClassName
  • 33. 

    You need to create a class that implements the Runnable interface to do background image processing. Out of the following list of method declarations, select the method that must satisfy the requirements.

    • A.

      Public void start()

    • B.

      Public void run()

    • C.

      Public void stop()

    • D.

      Public void suspend()

    Correct Answer
    B. Public void run()
  • 34. 

    Which of the following gives the set of Annotations declared in java.lang package?

    • A.

      @Retention, @Target

    • B.

      @Deprecated, @Override, @SuppressWarning

    • C.

      @Comment, @Class

    • D.

      @Documented, @Inherited

    Correct Answer
    B. @Deprecated, @Override, @SuppressWarning
  • 35. 

    Consider the following code:   class ABC { public void method1() { DEF def = new DEF(); def.method2(); } }   class DEF { public XYZ xyz;   public String method2() { return xyz.method3(); } }   class XYZ { public String value;   public String method3() { value = "XYZ"; return value; } }   class TestCode { public static void main(String args[]) { ABC abc = new ABC(); abc.method1(); } }   Which of the following will be the output if the above code is compiled and executed?

    • A.

      An exception is thrown at runtime

    • B.

      Prints: XYZ

    • C.

      Compilation fails

    • D.

      Prints: DEF

    • E.

      Prints: ABC

    Correct Answer
    A. An exception is thrown at runtime
  • 36. 

    To which of the following elements, annotations can be applied? (Choose 3)

    • A.

      Fields

    • B.

      Jar files

    • C.

      Classes

    • D.

      Methods

    • E.

      Class files

    Correct Answer(s)
    A. Fields
    C. Classes
    D. Methods
  • 37. 

    Consider the following scenario:   A Java application needs to stream a video from a movie file.   Which of the following options gives the correct combination of stream classes that can be used to implement the above requirement?

    • A.

      LineInputStream and BufferedInputStream

    • B.

      FileReader and BufferedReader

    • C.

      InputStreamReader and FileInputStream

    • D.

      FileInputStream and FilterInputStream

    • E.

      FileInputStream and BufferedInputStream

    Correct Answer
    E. FileInputStream and BufferedInputStream
  • 38. 

    Consider the following code:   public class SwitchIt { public static void main(String args[]) { int x = 10;   switch(x) { case 10: for(int i=0; i break;   case 20: System.out.println(x); break;   case 30: System.out.println(x*2); break;   default: System.out.println(x*3); } } }   Which of the following will be the output for the above program?

    • A.

      No output

    • B.

      10

    • C.

      11

    • D.

      30

    Correct Answer
    B. 10
  • 39. 

    Consider the following code:   class A { } class B extends A { } public class Code2 { public void method(A a) {   System.out.println("A"); } public void method(B b) { System.out.println("B"); } public static void main(String args[]) { new Code2().method(new Object()); } } Which of the following will be the output for the above code?

    • A.

      Prints: B

    • B.

      Throws ClassCastException at runtime

    • C.

      Compilation Error 'Cannot find the symbol'

    • D.

      Prints: A

    Correct Answer
    C. Compilation Error 'Cannot find the symbol'
  • 40. 

    Consider the following code snippet:   class Lock1 { Lock1() { } Lock1(Lock2 lock2) { this.lock2 = lock2; } Lock2 lock2; }   class Lock2 { Lock2() { } Lock2(Lock1 lock1) { this.lock1 = lock1; } Lock1 lock1; }   class GC6 { public static void main(String args[]) { Lock1 l1 = new Lock1(); Lock2 l2 = new Lock2(l1); l1.lock2 = l2; } }   Which of the objects are eligible for garbage collection in the above code?

    • A.

      None of the objects eligible

    • B.

      Lock1

    • C.

      Lock2

    • D.

      L1

    • E.

      L2

    Correct Answer(s)
    D. L1
    E. L2
  • 41. 

    Consider the following code snippet:   import java.io.*;   class Student { private String studentID; private String studentName;   public Student() { } public Student(String studentID, String studentName) { this.studentID = studentID; this.studentName = studentName; }   public String toString() { return "Student ID : " + studentID + " " + "Student Name : " + studentName; } }   public class IOCode3 { public static void main(String args[]) throws FileNotFoundException, IOException { ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("C:/ObjectData")); // Line 1 out.writeObject(new Student("100", "Student One")); // Line 2 out.close();   } }   What will be the output of the above code snippet?

    • A.

      Code will compile and execute without any error

    • B.

      Throws IOException at // Line 1

    • C.

      Throws IOException at // Line 2

    • D.

      Throws NotSerializableException at // Line 2

    • E.

      Throws NotSerializableException at // Line 1

    Correct Answer
    D. Throws NotSerializableException at // Line 2
  • 42. 

    Consider the following code snippet:   interface i1 { int i = 0; }   interface i2 { int i = 0; }   class inter implements i1, i2 { public static void main(String[] a) { System.out.println(i); } }   Which of the following options will be the output of the above code snippet?

    • A.

      No output

    • B.

      Prints: 0

    • C.

      Runtime Error

    • D.

      Compilation Error

    Correct Answer
    D. Compilation Error
  • 43. 

    Consider the following code:   1. class ExampleSix { 2. String msg = "Type is "; 3. public void showType(int n) { 4. String tmp; 5. if(n > 0) tmp = "positive"; 6. System.out.println(msg + tmp); 7. } 8. }   On running the above code it throws the compile-time error- the variable tmp is not initialised.   Which of the following changes to the above code will make the code to compile properly? (Choose 3)

    • A.

      Delcare the variable tmp as StringBuffer type

    • B.

      Declare the variable tmp as static

    • C.

      Insert the following line at line 6else tmp = "not positive";

    • D.

      Change line 4 as followsString tmp = null;

    • E.

      Remove line 4 and insert it at line 2

    Correct Answer(s)
    C. Insert the following line at line 6else tmp = "not positive";
    D. Change line 4 as followsString tmp = null;
    E. Remove line 4 and insert it at line 2
  • 44. 

    Consider the following code:   class One { public One() {   System.out.print(1); } } class Two extends One { public Two() { System.out.print(2); } } class Three extends Two { public Three() { System.out.print(3); } } public class Numbers { public static void main(String[] argv) { new Three(); } } Which of the following will be the output for the above program?

    • A.

      No output

    • B.

      123

    • C.

      321

    • D.

      32

    • E.

      3

    Correct Answer
    B. 123
  • 45. 

    Consider the following code snippet:   class Student { String studentID; String studentName; double score; }   The instances of the above defined class holds the information of individual   student. These details needs to be maintained in a data structure, that   * allows searching of student details using studentID * ascending order of Student objects based on studentID   Which of the following collection classes can be used to implement the above scenario?

    • A.

      TreeSet

    • B.

      HashMap

    • C.

      HashSet

    • D.

      ArrayList

    • E.

      TreeMap

    Correct Answer
    E. TreeMap

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Jul 30, 2011
    Quiz Edited by
    ProProfs Editorial Team
  • Apr 26, 2011
    Quiz Created by
    Unrealvicky
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.