Dd9

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Unrealvicky
U
Unrealvicky
Community Contributor
Quizzes Created: 6 | Total Attempts: 10,419
Questions: 45 | Attempts: 574

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

    Correct Answer(s)
    A. A. The output "Exception 2" 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
    Explanation
    The correct answer is a. The output "Exception 2" is because of the exception thrown programmatically. This is because the generateException() method throws an IllegalArgumentException, which is caught in the finally block and the message "Exception 2" is printed.

    The correct answer is c. The output "Exception 1" is because of the Exception thrown by JVM. This is because the line "System.out.println(s.length());" throws a NullPointerException since the variable "s" is null. This exception is caught in the catch block and the message "Exception 1" is printed.

    The correct answer is d. The Exception thrown by generateException() method is an Unchecked Exception. This is because the generateException() method throws an IllegalArgumentException, which is a type of RuntimeException and does not need to be declared in the method signature or caught in a try-catch block.

    Rate this question:

  • 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

    Correct Answer
    D. D. Prints: Caught Exception
    Explanation
    The code snippet creates an instance of the class Except and calls the method method2(). Inside method2(), the method method1() is called which throws a RuntimeException. Since there is a catch block specifically for RuntimeException before the catch block for Exception, the catch block for RuntimeException will be executed. Therefore, the output will be "Caught Exception".

    Rate this question:

  • 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;

    Correct Answer(s)
    C. C. String[][] s = new String[5][];
    D. D. String[][] s;
  • 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.

    Correct Answer
    D. D. It will compile but will not override the GenericFruit methodbecause of the different parameter list.
    Explanation
    The given scenario involves a junior programmer proposing to define an overriding method in the Apple class that has a different parameter list compared to the method in the GenericFruit class. This means that the method in the Apple class will not override the method in the GenericFruit class, even though it will still compile. Therefore, option d is the correct answer.

    Rate this question:

  • 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"

    Correct Answer
    B. B. Compiles and on executionPrints "Run method executed" thenthrows Runtime exception
    Explanation
    The program compiles successfully and executes without any errors. However, when the start() method is called twice on the same Thread object, it throws a Runtime exception (IllegalThreadStateException). This is because a Thread can only be started once, and calling start() multiple times on the same Thread object is not allowed. Therefore, the program will print "Run method executed" and then throw a Runtime exception.

    Rate this question:

  • 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

    Correct Answer
    A. A. Prints 0
    Explanation
    The program creates an instance of class A and starts a new thread. In the run() method of class A, the variable i is assigned the value 1. However, before the new thread has a chance to execute the run() method, the main thread continues to execute and prints the value of a.i, which is the default value of an int variable (0). Therefore, the output of the program will be 0.

    Rate this question:

  • 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

    Correct Answer
    C. C. Compilation error: cannot find the symbol
    Explanation
    The code will result in a compilation error because the variable 'v' is declared and initialized inside a block of code (an instance initializer) instead of the constructor. Therefore, the variable 'v' is not accessible outside of the instance initializer, and the 'codeMethod' method cannot access it. This leads to a compilation error stating that the symbol 'v' cannot be found.

    Rate this question:

  • 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

    Correct Answer(s)
    A. Answer:a. The String variable 'name' declared in line 3
    D. D. The int variable 'serialN' declared in line 5
    E. E. The int variable 'ID' declared in line 2
    Explanation
    The statement in line 8 would be able to use the String variable 'name' declared in line 3 because it is a public variable of the class Base. It would also be able to use the int variable 'serialN' declared in line 5 because it is a final variable within the methodA() method. Additionally, it would be able to use the int variable 'ID' declared in line 2 because it is a private static final variable of the class Base.

    Rate this question:

  • 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

    Correct Answer
    E. E. FileInputStream and BufferedInputStream
    Explanation
    The correct combination of stream classes that can be used to implement streaming a video from a movie file in a Java application is FileInputStream and BufferedInputStream. FileInputStream is used to read the raw bytes of the video file, while BufferedInputStream is used to improve performance by reading the file in chunks and buffering the input. This combination allows for efficient and smooth streaming of the video.

    Rate this question:

  • 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

    Correct Answer(s)
    A. It provides static factory class
    C. C. They provide hooks for custom implementations
    D. D. All major interfaces are supported
    Explanation
    Abstract implementations in Collections provide a static factory class, allowing for the creation of instances of the abstract implementation. They also provide hooks for custom implementations, allowing for customization and extension of the abstract implementation. Additionally, all major interfaces are supported by abstract implementations, ensuring compatibility with other classes and interfaces in the Collections framework.

    Rate this question:

  • 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

    Correct Answer
    D. D. Prints: 0,0,0.0,null
    Explanation
    The code initializes arrays of different data types (byte, long, float, and Object) with a length of 1. Since the arrays are not explicitly assigned any values, their default values are used. For byte and long arrays, the default value is 0. For float array, the default value is 0.0. For Object array, the default value is null. The code then prints the first element of each array, separated by commas. Therefore, the output will be "0,0,0.0,null".

    Rate this question:

  • 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

    Correct Answer
    D. D. Compilation Error
    Explanation
    The code snippet will result in a compilation error because both interfaces i1 and i2 have a variable named "i" with the same name and type. This causes an ambiguity as the class "inter" implements both interfaces, and the variable "i" becomes ambiguous. To resolve this ambiguity, the variable "i" should be accessed using the interface name followed by the variable name, for example, "i1.i" or "i2.i".

    Rate this question:

  • 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

    Correct Answer(s)
    C. C. protected
    E. E. public
    Explanation
    The correct modifiers that would allow the BigWidget class to access the setWidth method are "protected" and "public". The "protected" modifier allows access to the method within the same package and by subclasses, while the "public" modifier allows access from any other class.

    Rate this question:

  • 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

    Correct Answer(s)
    B. B. It is polymorphic
    D. D. Defined in the Object class
    E. E. Gives the String representation of an Object
    Explanation
    The correct answer choices are b, d, and e. The toString() method is polymorphic, meaning it can be overridden in subclasses to provide a different implementation. It is defined in the Object class, which is the root class for all Java classes. The purpose of the toString() method is to return a string representation of an object.

    Rate this question:

  • 15. 

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

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    The JDBC (Java Database Connectivity) API provides a set of classes and methods that allow Java applications to interact with databases. One of the functionalities provided by the JDBC API is the ability to create tables in a database. Therefore, it is true that it is possible to create a table using the JDBC API.

    Rate this question:

  • 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

    Correct Answer
    A. Answer:a. abc
    Explanation
    The code snippet creates a TreeMap object and adds three key-value pairs to it. The keys are "a", "b", and "c" and the corresponding values are "Hello", "Java", and "World" respectively. The iterator is then used to iterate over the keys in the TreeMap and print them. Since the keys are added in the order "a", "b", "c", the output will be "abc".

    Rate this question:

  • 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

    Correct Answer
    B. B. smile!..morning
    Explanation
    The program creates an object of the Exp4 class and calls the s1() method. The s1() method calls the s2() method, which in turn calls the s3() method. The s3() method throws an exception, which is caught by the catch block in the s1() method. In the catch block, the string s is appended with "morning". Finally, the value of s is printed, which is "smile!..morning". Therefore, the output of the program will be "smile!..morning".

    Rate this question:

  • 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)

    Correct Answer
    A. Answer:a. a = 10, b = 30
    Explanation
    The output of the code snippet will be "a = 10, b = 30". This is because the Test2 object t1 is serialized and written to a file using ObjectOutputStream. When it is deserialized using ObjectInputStream, the values of variables a and b are restored to their original values, which are 10 and 30 respectively. Therefore, when t2 is printed, it will display "a = 10, b = 30".

    Rate this question:

  • 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

    Correct Answer(s)
    C. C. java.lang
    D. D. java.lang.annotation
    Explanation
    The main packages for Annotations in Java are java.lang and java.lang.annotation. The java.lang package provides the fundamental classes and interfaces that are essential for basic language functionality. The java.lang.annotation package contains classes and interfaces that support annotation processing. These packages are important for working with annotations in Java programs.

    Rate this question:

  • 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

    Correct Answer
    C. C. 0 1 2 3 4
    Explanation
    The code uses nested loops to print numbers from 0 to 9. However, when i reaches 5, the "break loop" statement is executed, which causes the program to break out of the outer loop labeled "loop". This means that the inner loop will only execute until i reaches 5, and then the program will exit the outer loop. Therefore, the output will be "0 1 2 3 4".

    Rate this question:

  • 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

    Correct Answer
    C. C. Prints: Director Manirathnam directs filmsDirector Manirathnam also produces films
    Explanation
    The code snippet defines an abstract class "Director" with a protected variable "name" and an abstract method "occupation". It also defines a subclass "FilmDirector" that extends the "Director" class and implements the "occupation" method to print "Director " + name + " directs films".

    In the "TestDirector" class, an instance of "FilmDirector" is created with the name "Manirathnam" and the "occupation" method is called, which prints "Director Manirathnam directs films".

    Then, a new anonymous subclass of "Director" is created with the name "Manirathnam" and the "occupation" method is overridden to print "Director " + name + " also produces films". The "occupation" method of this anonymous subclass is called, which prints "Director Manirathnam also produces films".

    Therefore, the output of the code snippet will be "Director Manirathnam directs filmsDirector Manirathnam also produces films".

    Rate this question:

  • 22. 

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

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    Delimiters are not considered as tokens themselves. In programming or text processing, tokens are individual units of meaning that are separated by delimiters. Delimiters are characters used to separate or mark the boundaries between tokens. Therefore, the statement that delimiters themselves can be considered as tokens is false.

    Rate this question:

  • 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

    Correct Answer
    A. Answer:a. Map
    Explanation
    In this scenario, we need to associate each unique first name with the number of employees. A Map is best-suited for this as it allows us to store key-value pairs, where the first name can be the key and the number of employees can be the value. This way, we can easily retrieve the number of employees for each unique first name. Sets, queues, and lists do not provide the same key-value pair functionality as Maps, making them less suitable for this scenario.

    Rate this question:

  • 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

    Correct Answer
    E. E. abstract
    Explanation
    The modifier "abstract" cannot be applied to the declaration of a field (member of a class). The "abstract" modifier is used to declare abstract classes and methods, which cannot be instantiated and must be implemented by subclasses. Fields, on the other hand, are variables that store data and do not have the concept of being abstract. Therefore, the "abstract" modifier is not applicable to fields.

    Rate this question:

  • 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

    Correct Answer
    D. D. Types
    Explanation
    The class "Types" in the java.sql package maps the SQL data types to Java datatypes.

    Rate this question:

  • 26. 

    26 Which of the following codes will compile and run properly?

    • A.

      Answer:a. public class Test1 {public static void main() {System.out.println("Test1");}}

    • B.

      B. public class Test2 {static public void main(String[] in) {System.out.println("Test2");}}

    • C.

      C. public class Test3 {public static void main(String args) {System.out.println("Test3");}}

    • D.

      D. public class Test4 {static int main(String args[]) {System.out.println("Test4");}}

    • E.

      E. public class Test5 {static void main(String[] data) {System.out.println("Test5");}}

    Correct Answer
    B. B. public class Test2 {static public void main(String[] in) {System.out.println("Test2");}}
    Explanation
    The correct answer is b. The code in option b will compile and run properly because it follows the correct syntax for the main method in Java. The main method must be declared as public, static, and void, and it must accept a String array as a parameter. In option b, the main method is declared as static public void main(String[] in), which meets these requirements. The code will print "Test2" when executed.

    Rate this question:

  • 27. 

    Consider the following code: public class WrapIt { public static void main(String[] args) { new WrapIt().testC('a'); } public void testC(char ch) { Integer ss = new Integer(ch); Character cc = new Character(ch); if(ss.equals(cc)) System.out.print("equals "); if(ss.intValue()==cc.charValue()) { System.out.println("EQ"); } } } Which of the following gives the valid output for the above code?

    • A.

      A. Prints: equals

    • B.

      B. Compile-time error: Integer wrapper cannot accept char type

    • C.

      c. Prints: EQ

    • D.

      D. Compile-time error: Wrapper types cannot be compared using equals

    • E.

      E. Prints: equals EQ

    Correct Answer
    C. c. Prints: EQ
    Explanation
    The code creates an instance of the WrapIt class and calls the testC method with the character 'a' as an argument. Inside the testC method, the character 'a' is wrapped in an Integer object and a Character object.

    The first if statement checks if the Integer object and the Character object are equal using the equals method. Since the Character object represents the same character as the Integer object, the condition is true and "equals" is printed.

    The second if statement compares the integer value of the Integer object with the character value of the Character object. Since the integer value of 'a' is equal to the character value of 'a', the condition is true and "EQ" is printed.

    Therefore, the valid output for the above code is "EQ".

    Rate this question:

  • 28. 

    Which of the following statements are valid 3 dimensional character array creations?(Choose 2)

    • A.

      A. char[][][] charArray = {{'a', 'b'}, {'c', 'd'}, {'e', 'f'}};

    • B.

      B. char[][][] charArray = {{{'a', 'b'}, {'c', 'd'}, {'e', 'f'}}};

    • C.

      C. char[][][] charArray = {{'a', 'b'}, {'c', 'd'}, {'e'}};

    • D.

      D. char[][][] charArray = new char[2][2][];

    • E.

      E. char[2][2][] charArray = {'a', 'b'};

    Correct Answer(s)
    B. B. char[][][] charArray = {{{'a', 'b'}, {'c', 'd'}, {'e', 'f'}}};
    D. D. char[][][] charArray = new char[2][2][];
    Explanation
    Option b is a valid 3-dimensional character array creation because it uses three sets of curly braces to define the dimensions and initialize the array with characters.

    Option d is also valid because it declares a 3-dimensional character array with dimensions [2][2][] using the "new" keyword, allowing for later initialization of the array.

    The other options either have incorrect syntax or do not create a valid 3-dimensional character array.

    Rate this question:

  • 29. 

    29 Consider the following class definition: class InOut{ String s= new String("Between"); public void amethod(final int iArgs){ int iam; class Bicycle{ public void sayHello(){ ...Line 1 } }//End of bicycle class }//End of amethod public void another(){ int iOther; } } Which of the following statements would be correct to be coded at ...Line 1? (Choose 2)

    • A.

      A. System.out.println(iArgs);

    • B.

      B. System.out.println(iam);

    • C.

      C. System.out.println(iOther);

    • D.

      D. System.out.println(s);

    Correct Answer(s)
    A. A. System.out.println(iArgs);
    D. D. System.out.println(s);
  • 30. 

    Consider s1 and s2 are sets. Which of the following options gives the exact meaning of the method call s1.retainAll(s2)?

    • A.

      A. transforms s1 into the union of s1 and s2

    • B.

      B. transforms s1 into the intersection of s1 and s2.

    • C.

      C. transforms s1 into the (asymmetric) set difference of s1 and s2

    • D.

      D. copies elements from s2 to s1

    • E.

      E. returns true if s2 is a subset of s131

    Correct Answer
    B. B. transforms s1 into the intersection of s1 and s2.
    Explanation
    The method call s1.retainAll(s2) transforms s1 into the intersection of s1 and s2. This means that after the method call, s1 will only contain the elements that are present in both s1 and s2. Any elements that are not common to both sets will be removed from s1.

    Rate this question:

  • 31. 

    Which of the following annotations are defined in java.lang package?

    • A.

      A. @SuppressWarnings

    • B.

      B. @Target

    • C.

      C. @Retention

    • D.

      D. @Override

    • E.

      E. @Deprecated

    Correct Answer(s)
    A. A. @SuppressWarnings
    D. D. @Override
    E. E. @Deprecated
    Explanation
    The annotations @SuppressWarnings, @Override, and @Deprecated are defined in the java.lang package. These annotations are used to provide additional information or instructions to the compiler or runtime environment. @SuppressWarnings is used to suppress compiler warnings, @Override is used to indicate that a method overrides a superclass method, and @Deprecated is used to mark a method or class as deprecated, indicating that it should no longer be used. @Target and @Retention are not defined in the java.lang package.

    Rate this question:

  • 32. 

    Consider the following code: class Test { Test(int i) { System.out.println("Test(" + i +")"); } } public class Question{ static Test t1 = new Test(1); Test t2 = new Test(2); static Test t3 = new Test(3); public static void main(String[] args){ Question Q = new Question(); } } Which of the following options gives the correct order of initialization?

    • A.

      A. Test(3)Test(2)Test(1)

    • B.

      B. Test(2)Test(1)Test(3)

    • C.

      C. Test(1)Test(2)Test(3)

    • D.

      D. Test(1)Test(3)Test(2)

    Correct Answer
    D. D. Test(1)Test(3)Test(2)
    Explanation
    The correct order of initialization in this code is Test(1), Test(3), Test(2). This is because the static variable t1 is initialized first, followed by the static variable t3. Then, the main method is called and an instance of the Question class is created, which initializes the instance variable t2. Therefore, the output will be "Test(1)", "Test(3)", "Test(2)".

    Rate this question:

  • 33. 

    Which of the following methods is used to check whether ResultSet object contains records?

    • A.

      A. first()

    • B.

      B. hasRecords()

    • C.

      C. next()

    • D.

      D. last()

    • E.

      E. previous()

    Correct Answer
    C. C. next()
    Explanation
    The method used to check whether a ResultSet object contains records is the "next()" method. This method moves the cursor to the next row in the ResultSet and returns true if there is a next row, indicating that the ResultSet contains records. If there are no more rows, the method returns false. The other options mentioned in the question (first(), hasRecords(), last(), previous()) are not used for checking the presence of records in a ResultSet.

    Rate this question:

  • 34. 

    Which of the following options are true about Associations?(choose 2)

    • A.

      A. In Associations, cardinality refers to the number of relatedobjects

    • B.

      B. Association refers to binding of related data and behavioursinto a single entity

    • C.

      C. Associations are bi-directional

    • D.

      D. Association refers to a class reuses the properties andmethods of another class

    • E.

      E. Association refers to an object composed of set of otherobjects

    Correct Answer(s)
    A. A. In Associations, cardinality refers to the number of relatedobjects
    C. C. Associations are bi-directional
    Explanation
    The correct answer choices are a and c. In associations, cardinality refers to the number of related objects, indicating how many objects are associated with each other. Associations are also bi-directional, meaning that the relationship between objects can be traversed in both directions.

    Rate this question:

  • 35. 

    Consider the following code snippet: class TestString4 { public static void main(String args[]) { String s1 = "Its Great"; String s2 = "Its Tricky"; System.out.print(s1.concat(s2).length() + " "); System.out.print(s1.concat(s2.substring(1, s1.length())).length()); } } What will be the output of the following code snippet?

    • A.

      A. 18 20

    • B.

      B. 17 19

    • C.

      C. 20 18

    • D.

      D. 17 17

    • E.

      E. 19 17

    Correct Answer
    E. E. 19 17
    Explanation
    The code snippet first concatenates s1 and s2 using the concat() method, resulting in the string "Its GreatIts Tricky". The length of this string is 19.

    Then, it concatenates s1 and a substring of s2 starting from index 1 and ending at the length of s1. This results in the string "Its Greatts Tricky", and the length of this string is 17.

    Therefore, the output of the code snippet will be "19 17".

    Rate this question:

  • 36. 

    Consider the following code: class Planet { } class Earth extends Planet { } public class WelcomePlanet { public static void welcomePlanet(Planet planet) { if (planet instanceof Earth) { System.out.println("Welcome!"); } else if (planet instanceof Planet) { System.out.println("Planet!"); } else { System.exit(0); } } public static void main(String args[]) { WelcomePlanet wp = new WelcomePlanet(); Planet planet = new Earth(); welcomePlanet(planet); } } Which of the following will be the output of the above program? Answer:

    • A.

      A. An exception is thrown at runtime

    • B.

      B. The code runs with no output

    • C.

      C. Welcome!

    • D.

      D. Planet!

    • E.

      E. Compilation fails

    Correct Answer
    C. C. Welcome!
    Explanation
    The output of the program will be "Welcome!" because the variable "planet" is of type Earth, which is a subclass of Planet. Therefore, the condition "planet instanceof Earth" is true and the corresponding message "Welcome!" is printed. The condition "planet instanceof Planet" is also true, but since it is the second condition in the if-else statement, it will not be executed.

    Rate this question:

  • 37. 

    What methods does the java.lang.Runtime class provide related to memory management?(Choose 3)

    • A.

      A. to invoke Garbage collector

    • B.

      B. to create new memory locations

    • C.

      C. to query the total memory and free memory

    • D.

      D. to dump the objects to storage device

    • E.

      E. to run finalize methods explicitly

    Correct Answer(s)
    A. A. to invoke Garbage collector
    C. C. to query the total memory and free memory
    E. E. to run finalize methods explicitly
    Explanation
    The java.lang.Runtime class provides three methods related to memory management. The first method is used to invoke the garbage collector, which helps in releasing memory occupied by unreferenced objects. The second method is used to query the total memory and free memory available in the system, which can be helpful in monitoring memory usage. The third method allows running finalize methods explicitly, which can be useful in performing cleanup operations before an object is garbage collected.

    Rate this question:

  • 38. 

    Which of the following statement is true?

    • A.

      A. To call the wait() method, a thread must own the lock of theobject on which the call is to be made.

    • B.

      B. To call the yield() method, a thread must own the lock of theobject on which the call is to be made.

    • C.

      C. To call the sleep() method, a thread must own the lock of theobject which the call is to be made.

    • D.

      D. To call the wait() method, a thread must own the lock of thecurrent thread.

    • E.

      E. To call the join() method, a thread must own the lock of theobject on which the call is to be made

    • F.

      E. JVM thrown exceptions can be thrown programmatically

    Correct Answer
    A. A. To call the wait() method, a thread must own the lock of theobject on which the call is to be made.
    Explanation
    The correct answer is a. To call the wait() method, a thread must own the lock of the object on which the call is to be made. This statement is true because the wait() method is used for inter-thread communication in Java and can only be called by a thread that holds the lock of the object it is called on. The wait() method releases the lock and waits for another thread to notify it before it can resume execution.

    Rate this question:

  • 39. 

    Which of the following statements are true? (Choose 2) Answer:

    • A.

      A. All exceptions are thrown by JVM

    • B.

      B. All RuntimeException are thrown by JVM

    • C.

      C. JVM cannot throw user-defined exceptions

    • D.

      D. All exceptions are thrown programmatically from the code orAPI

    • E.

      E. JVM thrown exceptions can be thrown programmatically

    • F.

      F.NARAYANAN M.E.,M.S.,

    Correct Answer(s)
    C. C. JVM cannot throw user-defined exceptions
    E. E. JVM thrown exceptions can be thrown programmatically
  • 40. 

    Consider the following code: public class UnwiseThreads implements Runnable { public void run() { while(true) { } } public static void main(String args[]) { UnwiseThreads ut1 = new UnwiseThreads(); UnwiseThreads ut2 = new UnwiseThreads(); UnwiseThreads ut3 = new UnwiseThreads(); ut1.run(); ut2.run(); ut3.run(); } } Which of the following is correct for the above given program? Answer:

    • A.

      A. The code compiles and runs 3 non ending non daemon threads

    • B.

      B. The code compiles but runs only 1 non ending, non daemon thread

    • C.

      C. Runtime Error "IllegalThreadStateException"

    • D.

      D. Compilation error "ut2.run() is never reached"

    Correct Answer
    B. B. The code compiles but runs only 1 non ending, non daemon thread
    Explanation
    The code compiles and runs 3 non ending non daemon threads.

    Rate this question:

  • 41. 

    Which of the following options is true about multi-level inheritance? Answer:

    • A.

      A. Inheriting from two super classes

    • B.

      B. Inheriting from a class which is already in an inheritance hierarchy

    • C.

      C. Inheriting from more than one super class

    • D.

      D. Inheriting from a single class

    • E.

      E.thigil pandi

    Correct Answer
    B. B. Inheriting from a class which is already in an inheritance hierarchy
    Explanation
    Multi-level inheritance refers to a situation where a class inherits from a class that is already part of an inheritance hierarchy. In other words, the derived class is inheriting from a class that has already inherited from another class. This allows for the creation of a hierarchical structure where each class inherits properties and behaviors from its parent classes. In this case, option b is true because it accurately describes the concept of multi-level inheritance.

    Rate this question:

  • 42. 

    Anonymous class can have their own members. State True or False.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    Anonymous classes in programming languages can indeed have their own members. These members can include variables, methods, and even inner classes. Anonymous classes are typically used when a class needs to be defined and instantiated in a single expression, without the need for a separate named class. These classes are often used for implementing interfaces or extending abstract classes on the fly. The members of an anonymous class are accessible within the class itself and can be used to define behavior specific to that instance of the anonymous class.

    Rate this question:

  • 43. 

    Consider the following partial code: interface A { public int getValue(); } class B implements A { public int getValue() { return 1; } } class C extends B { // insert code here } Which of the following code fragments, when inserted individually at the commented line (// insert code here), makes use of polymorphism? (Choose 3)

    • A.

      A. public void add(A a) { a.getValue(); }

    • B.

      B. public void add(B b) { b.getValue(); }

    • C.

      C. public void add(C c1, C c2) { c1.getValue(); }

    • D.

      D. public void add(C c) { c.getValue(); }

    • E.

      E. public void add(A a, B b) { a.getValue(); }

    Correct Answer(s)
    A. A. public void add(A a) { a.getValue(); }
    B. B. public void add(B b) { b.getValue(); }
    E. E. public void add(A a, B b) { a.getValue(); }
    Explanation
    The correct answers for this question are options a, b, and e. These options make use of polymorphism because they accept objects of different classes that implement the interface A. This allows for flexibility in the types of objects that can be passed to the methods. Option a accepts an object of type A, option b accepts an object of type B, and option e accepts objects of types A and B. All three options call the getValue() method, which is defined in the interface A and implemented in the classes B and C.

    Rate this question:

  • 44. 

    From JDK 1.6, which of the following interfaces is also implemented by java.util.TreeMap class?

    • A.

      A. NavigableMap

    • B.

      B. NavigableSet

    • C.

      C. NavigableList

    • D.

      D. Deque

    • E.

      E.gillete

    Correct Answer
    A. A. NavigableMap
    Explanation
    From JDK 1.6, the java.util.TreeMap class also implements the NavigableMap interface. This means that TreeMap can be navigated in both ascending and descending order, and it provides additional methods for navigation and retrieval based on the closest matches to given search targets. This interface allows TreeMap to have more advanced navigation capabilities compared to the basic Map interface.

    Rate this question:

  • 45. 

    Consider the following code snippet: class Node { Node node; } class NodeChain { public static void main(String a[]) { Node node1 = new Node(); // Line 1 node1.node = node1; // Code here } } Which of the following code snippets when replaced at the comment line (// Code Here) in the above code will make the object created at Line 1, eligible for garbage collection? (Choose 2)

    • A.

      A. node1.node = null;

    • B.

      B. node1 = node1.node;

    • C.

      C. node1.node = new Node();

    • D.

      D. node1 = null;

    • E.

      E. node1 = new Node();

    • F.

      F.sothika

    Correct Answer(s)
    D. D. node1 = null;
    E. E. node1 = new Node();
    Explanation
    The code snippet at Line 1 creates a new Node object and assigns it to the variable node1. At Line 2, the node1.node reference is set to point to the same Node object, creating a circular reference.

    In order to make the object eligible for garbage collection, we need to remove all references to it.

    Option d. node1 = null; sets the node1 reference to null, effectively removing the reference to the Node object.

    Option e. node1 = new Node(); creates a new Node object and assigns it to the node1 reference, replacing the previous reference to the object created at Line 1. This also removes the reference to the original object, making it eligible for garbage collection.

    Rate this question:

Quiz Review Timeline +

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

  • Current Version
  • Mar 22, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Apr 27, 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.