Dd9

45 Questions | Total Attempts: 553

SettingsSettingsSettings
Dd9 - Quiz

Questions and Answers
  • 1. 
    public class ExceptionType { public static void main(String args[]) { String s = null; try { System.out.println(s.length()); } catch(Exception e) { System.out.println("Exception 1"); } finally { try { generateException(); } catch(Exception e) { System.out.println("Exception 2"); } } } static void generateException() throws IllegalArgumentException { throw new IllegalArgumentException(); } }
    • A. 

      A. The output "Exception 2" is because of the exception thrownprogrammatically

    • B. 

      B. The output "Exception 1" is because of the Exception thrownprogrammatically

    • C. 

      C. The output "Exception 1" is because of the Exception thrownby JVM

    • D. 

      D. The Exception thrown by generateException() method is anUnchecked Exception

    • E. 

      E. The output "Exception 2" is because of the Exception thrownby JVM

  • 2. 
    public class Except { private void method1() throws Exception { throw new RuntimeException(); } public void method2() { try { method1(); } catch (RuntimeException e) { System.out.println("Caught Exception"); } catch (Exception e) { System.out.println("Caught Runtime Exception"); } } public static void main(String args[]) { Except e = new Except(); e.method2(); } }
    • A. 

      A. No output

    • B. 

      B. Compile time error

    • C. 

      C. Prints: Caught Runtime Exception

    • D. 

      D. Prints: Caught Exception

  • 3. 
    3 Which of the following statements are true about String Arrays? (Choose 2)
    • A. 

      A. Array index can be a long value

    • B. 

      B. Array index can be a negative value

    • C. 

      C. String[][] s = new String[5][];

    • D. 

      D. String[][] s;

    • E. 

      E. Array decaration: String[6] strarray;

  • 4. 
    4 Consider the following scenario: The GenericFruit class defines the following method to return a float value: public float calories( float serving ) { // code goes here } A junior programmer writing the Apple class, which extends GenericFruit, proposes to define the following overriding method: public double calories( double serving ) { // code goes here } Which of the following statement is True regarding the above scenario?
    • A. 

      A. It will not compile because of the different return type.

    • B. 

      B. It will not compile because of the different input type in theparameter list.

    • C. 

      C. The double version overrides the float version.

    • D. 

      D. It will compile but will not override the GenericFruit methodbecause of the different parameter list.

  • 5. 
    5 Consider the following program: public class TestStart implements Runnable { boolean stoper = true; public void run() { System.out.println ("Run method Executed"); } public static void main (String[] argv) { TestStart objInt = new TestStart(); Thread threadX = new Thread(objInt); threadX.start(); threadX.start(); } }
    • A. 

      A. Compiles and executes successfullyPrints "Run method executed"

    • B. 

      B. Compiles and on executionPrints "Run method executed" thenthrows Runtime exception

    • C. 

      C. Compilation Error

    • D. 

      D. Compiles and on executionPrints "Run method executed"

  • 6. 
    6 Consider the following program: class A extends Thread { private int i; public void run() {i = 1;} public static void main(String[] args) { A a = new A(); a.start(); System.out.print(a.i); } } What will be the output of the above program?
    • A. 

      A. Prints 0

    • B. 

      B. Prints: 01

    • C. 

      C. Prints: 10

    • D. 

      D. Prints 1

    • E. 

      E. Compile-time error

  • 7. 
    7 Consider the following code: import java.util.*; public class Code10 { { final Vector v; v=new Vector(); } public Code10() { } public void codeMethod() { System.out.println(v.isEmpty()); } public static void main(String args[]) { new Code10().codeMethod(); } } Which of the following will be the output for the above code?
    • A. 

      A. Runtime error: NullPointerException

    • B. 

      B. Prints: false

    • C. 

      C. Compilation error: cannot find the symbol

    • D. 

      D. Prints: true

    • E. 

      E. Compilation error: v is not initialised inside the constructor

  • 8. 
    8 Consider the following code: In the following code methodA has an inner class 1. public class Base { 2. private static final int ID = 3; 3. public String name; 4. public void methodA( int nn ){ 5. final int serialN = 11; 6. class inner { 7. void showResult(){ 8. System.out.println( "Rslt= " + XX ); 9. } 10. } // end class inner 11. new inner().showResult(); 12. } // end methodA 13. ) Which of the following variables would the statement in line 8 be able to use in place of XX? (Choose 3)
    • A. 

      Answer:a. The String variable 'name' declared in line 3

    • B. 

      B. Invoking methodA() defined in line 4

    • C. 

      C. The int variable 'nn' declared in line 4

    • D. 

      D. The int variable 'serialN' declared in line 5

    • E. 

      E. The int variable 'ID' declared in line 2

  • 9. 
    9 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. 

      Answer:a. InputStreamReader and FileInputStream

    • B. 

      B. FileInputStream and FilterInputStream

    • C. 

      C. LineInputStream and BufferedInputStream

    • D. 

      D. FileReader and BufferedReader

    • E. 

      E. FileInputStream and BufferedInputStream

  • 10. 
    10 Which of the following options are true about abstract implementations in Collections?(choose 3)
    • A. 

      It provides static factory class

    • B. 

      B. All major implementations like Hashtable, Vectors aresupported

    • C. 

      C. They provide hooks for custom implementations

    • D. 

      D. All major interfaces are supported

    • E. 

      E. Map is not supported

  • 11. 
    11 Consider the following code: class AT1 { public static void main (String[] args) { byte[] a = new byte[1]; long[] b = new long[1]; float[] c = new float[1]; Object[] d = new Object[1]; System.out.print(a[0]+","+b[0]+","+c[0]+","+d[0]); } } Which of the following will be the output of the above code?
    • A. 

      Answer:a. Prints: 0,0,0,null

    • B. 

      B. None of the listed options

    • C. 

      C. Run-time error

    • D. 

      D. Prints: 0,0,0.0,null

    • E. 

      E. Compile-time error

  • 12. 
    12 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. 

      Answer:a. Runtime Error

    • B. 

      B. Prints: 0

    • C. 

      C. No output

    • D. 

      D. Compilation Error

  • 13. 
    13 The following class definitions are in separate files. Note that the Widget and BigWidget classes are in different packages: 1. package conglomo; 2. public class Widget extends Object{ 3. private int myWidth; 4. XXXXXX void setWidth( int n ) { 5. myWidth = n; 6. } 7. } // the following is in a separate file and in separate package 8. package conglomo.widgets; 9. import conglomo.Widget ; 10. public class BigWidget extends Widget { 11. BigWidget() { 12. setWidth( 204 ); 13. } 14. } Which of the following modifiers, used in line 4 instead of XXXXXX, would allow the BigWidget class to access the setWidth method (as in line 12)? (Choose 2)
    • A. 

      Answer:a. final

    • B. 

      B. default (blank), that is, the method declaration would readvoid setWidth( int n )

    • C. 

      C. protected

    • D. 

      D. private

    • E. 

      E. public

  • 14. 
    14 Which of the following statements are true regarding toString() method?(Choose 3)
    • A. 

      Answer:a. Declared in the Object class

    • B. 

      B. It is polymorphic

    • C. 

      C. Essential for inheriting a class

    • D. 

      D. Defined in the Object class

    • E. 

      E. Gives the String representation of an Object

  • 15. 
    5 It is possible to create a table using JDBC API. State True or False.
    • A. 

      True

    • B. 

      False

  • 16. 
    16 Consider the following code snippet: import java.util.*; public class TestCol8{ public static void main(String argv[]){ TestCol8 junk = new TestCol8(); junk.sampleMap(); } public void sampleMap(){ TreeMap tm = new TreeMap(); tm.put("a","Hello"); tm.put("b","Java"); tm.put("c","World"); Iterator it = tm.keySet().iterator(); while(it.hasNext()){ System.out.print(it.next()); } } } What will be the output of the above code snippet?
    • A. 

      Answer:a. abc

    • B. 

      B. Runtime error

    • C. 

      C. HWJ

    • D. 

      D. HelloJavaWorld

    • E. 

      E. Compile error

  • 17. 
    17 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. 

      A. smile!..morningevening

    • B. 

      B. smile!..morning

    • C. 

      C. smile!..

    • D. 

      D. smile!..eveningmorning

    • E. 

      E. smile!..morningeveninggood

  • 18. 
    18 Consider the following code snippet: import java.io.*; class Test { int a = 10; } class Test2 extends Test implements Serializable { int b; public String toString() { return "a = " + a + ", " + "b = " + b; } } public class IOCode5 { public static void main(String args[]) throws FileNotFoundException, IOException, ClassNotFoundException { ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("C:/ObjectData")); Test2 t1 = new Test2(); t1.a = 20; t1.b = 30; out.writeObject(t1); out.close(); ObjectInputStream in = new ObjectInputStream(new FileInputStream("C:/ObjectData")); Test2 t2 = (Test2) in.readObject(); // Line 1 System.out.println(t2); } } What will be the output of the above code snippet?
    • A. 

      Answer:a. a = 10, b = 30

    • B. 

      B. a = 0, b = 30

    • C. 

      C. a = 20, b = 30

    • D. 

      D. a = 10, b = 0

    • E. 

      E. throws TransientException at the commented line (// Line 1)

  • 19. 
    19 Which of the following are main packages for Annotations?(Choose 2)
    • A. 

      Answer:a. java.io

    • B. 

      B. java.util

    • C. 

      C. java.lang

    • D. 

      D. java.lang.annotation

    • E. 

      E. java.sql

  • 20. 
    20 Consider the following code: public class LabeledBreak2 { public static void main(String args[]) { loop: for(int j=0; j<2; j++) { for(int i=0; i<10; i++) { if(i == 5) break loop; System.out.print(i + " "); } } } } Which of the following will be the output for the above code?
    • A. 

      Answer:a. 0 1 2 3 4 0 1 2 3 4

    • B. 

      B. 0 1 2 3 4 5

    • C. 

      C. 0 1 2 3 4

    • D. 

      D. 1 2 3 4 5

    • E. 

      E. Indefinite Loop

  • 21. 
    21 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. 

      Answer:a. Compilation fails at TestDirector class

    • B. 

      B. Prints: Director Manirathnam also produces films

    • C. 

      C. Prints: Director Manirathnam directs filmsDirector Manirathnam also produces films

    • D. 

      D. Prints: Director Manirathnam directs films

    • E. 

      E. Runtime Error

  • 22. 
    22 Delimiters themselves be considered as tokens. State True or False.
    • A. 

      True

    • B. 

      False

  • 23. 
    23 Consider the following scenario: A company decides that it only wants to use the most popular names for its products. You have to give the number of employees against each unique first name. Which of the following four core interfaces is best-suited for implementing the above scenario?
    • A. 

      Answer:a. Map

    • B. 

      B. Set

    • C. 

      C.queue

    • D. 

      D.list

  • 24. 
    24 Which of the following modifier cannot be applied to the declaration of a field (member of a class)?
    • A. 

      Answer:a. protected

    • B. 

      B. private

    • C. 

      C. final

    • D. 

      D. public

    • E. 

      E. abstract

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

      Answer:a. JDBCTypes

    • B. 

      B. JDBCSQLTypes

    • C. 

      C. No explicit data type mapping. Automatically mapped onQuery Call.

    • D. 

      D. Types

    • E. 

      E. SQLTypes

Back to Top Back to top