Dd

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,430
Questions: 44 | Attempts: 505

SettingsSettingsSettings
Dd - Quiz

Questions and Answers
  • 1. 

    Which of the following are true about ResultSet? (Choose 2)  

    • A.

      Atleast one record should be there in the ResultSet onopening a query (or) table

    • B.

      Not all ResultSets are updatable

    • C.

      The ResultSet object contains null, if there are no records inthe table

    • D.

      It is possible to delete records through ResultSet

    • E.

      All ResultSet, are Scrollable

    Correct Answer(s)
    B. Not all ResultSets are updatable
    D. It is possible to delete records through ResultSet
    Explanation
    Not all ResultSets are updatable because some ResultSets may be read-only and cannot be modified. It is possible to delete records through ResultSet because the ResultSet object provides methods for deleting rows from the underlying table.

    Rate this question:

  • 2. 

    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.

      Prints: false

    • B.

      Runtime error: NullPointerException

    • C.

      Compilation error: cannot find the symbol

    • D.

      Compilation error: v is not initialised inside the constructor

    • E.

      Prints: true

    Correct Answer
    C. Compilation error: cannot find the symbol
    Explanation
    The code will produce a compilation error: cannot find the symbol. This is because the variable "v" is declared and initialized within the instance initializer block, which is executed before the constructor. Therefore, the variable "v" is not accessible within the constructor or any other methods in the class. As a result, when the code tries to access "v" in the codeMethod() method, it cannot find the symbol and a compilation error occurs.

    Rate this question:

  • 3. 

    Consider the following scenario: Mr.Vijay is working for a Software Company. He needs to save and reload objects from a Java application. He needs to write a module to accomplish the same. Which of the following options can be used to accomplish the above requirement?

    • A.

      Writable interface

    • B.

      Readable interface

    • C.

      ObjectSerializable interface

    • D.

      Cloneable interface

    • E.

      Serializable interface

    Correct Answer
    E. Serializable interface
    Explanation
    The Serializable interface can be used to accomplish the requirement of saving and reloading objects from a Java application. This interface allows objects to be converted into a byte stream, which can then be saved to a file or transferred over a network. The byte stream can also be deserialized back into an object, allowing it to be reloaded. This makes the Serializable interface a suitable choice for Mr. Vijay to implement in his module.

    Rate this question:

  • 4. 

    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.

      System.out.println(iOther);

    • B.

      System.out.println(iam);

    • C.

      System.out.println(iArgs);

    • D.

      System.out.println(s);

    Correct Answer(s)
    C. System.out.println(iArgs);
    D. System.out.println(s);
  • 5. 

    Which of the following modifiers cannot be used with the abstract modifier in a method declaration?(Choose 3)

    • A.

      Synchronized

    • B.

      Final

    • C.

      Public

    • D.

      Protected

    • E.

      Private

    Correct Answer(s)
    A. Synchronized
    B. Final
    E. Private
    Explanation
    The abstract modifier is used to indicate that a method does not have an implementation and must be overridden in a subclass. The synchronized modifier is used to ensure that only one thread can access a method at a time. Since an abstract method cannot have an implementation, it does not make sense to synchronize it. The final modifier is used to indicate that a method cannot be overridden, but abstract methods are meant to be overridden, so the final modifier cannot be used with the abstract modifier. The private modifier restricts access to a method, but abstract methods are meant to be accessed by subclasses, so the private modifier cannot be used with the abstract modifier.

    Rate this question:

  • 6. 

    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.

      0 1 2 3 4 5

    • B.

      Indefinite Loop

    • C.

      1 2 3 4 5

    • D.

      0 1 2 3 4

    • E.

      0 1 2 3 4 0 1 2 3 4

    Correct Answer
    D. 0 1 2 3 4
    Explanation
    The code contains a nested loop. The outer loop runs two times and the inner loop runs ten times. Inside the inner loop, there is a condition that checks if the value of 'i' is equal to 5. If it is, the 'break loop' statement is executed, which breaks out of both the inner and outer loops. Therefore, when 'i' reaches 5, the loop is terminated and the program prints the numbers 0 to 4. Hence, the output of the code will be "0 1 2 3 4".

    Rate this question:

  • 7. 

    Consider the following code: public class Key1 { public boolean testAns( String ans, int n ) { boolean rslt; if (ans.equalsIgnoreCase("YES") & n > 5) rslt = true; return rslt; } public static void main(String args[]) { System.out.println(new Key1().testAns("no", 5)); } } Which of the following will be the output of the above program?

    • A.

      NO

    • B.

      True

    • C.

      Compile-time error

    • D.

      Runtime Error

    • E.

      False

    Correct Answer
    C. Compile-time error
    Explanation
    The code will result in a compile-time error because the variable "rslt" is not initialized before it is returned.

    Rate this question:

  • 8. 

    Which of the following is the immediate super interface of CallableStatement?

    • A.

      CallableStatement

    • B.

      PreparedStatement

    • C.

      ResultSet

    • D.

      Statement

    • E.

      Connection

    Correct Answer
    B. PreparedStatement
    Explanation
    The immediate super interface of CallableStatement is PreparedStatement. This is because CallableStatement is a subinterface of PreparedStatement, which is a subinterface of Statement. Therefore, PreparedStatement is the direct parent interface of CallableStatement.

    Rate this question:

  • 9. 

    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?

    • A.

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

    • B.

      The code compiles and runs 3 non ending non daemon threads

    • C.

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

    • D.

      Runtime Error "IllegalThreadStateException"

    Correct Answer
    C. The code compiles but runs only 1 non ending, non daemon thread
    Explanation
    The code compiles without any errors. In the main method, three instances of the UnwiseThreads class are created. However, instead of starting the threads using the start() method, the run() method is called directly on each instance. This means that the code runs sequentially and does not create separate threads. Therefore, only one thread is executed, resulting in the code running only 1 non-ending, non-daemon thread.

    Rate this question:

  • 10. 

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

    • A.

      LinkedHashSet

    • B.

      TreeSet

    • C.

      Hashtable

    • D.

      SortedSet

    • E.

      HashSet

    Correct Answer
    E. HashSet
    Explanation
    HashSet is the best-performing implementation of the Set interface because it offers constant time performance for basic operations such as add, remove, and contains. It achieves this by using a hash table to store elements, which allows for efficient lookup and retrieval. HashSet does not maintain any specific order of elements, making it faster compared to other implementations like LinkedHashSet or TreeSet, which have additional overhead for maintaining insertion order or sorting elements. Hashtable is not a recommended implementation for Set interface as it is a synchronized class, which can impact performance in multi-threaded environments. SortedSet is an interface, not an implementation, so it cannot be considered as the best-performing implementation.

    Rate this question:

  • 11. 

    12 Consider the following scenario: Real Chocos Private Limited deals in manufacturing variety of chocolates. This organization manufactures three varieties of chocolates. 1. Fruit Chocolates 2. Rum Chocolates 3. Milk Chocolates A software system needs to be built. Which of the following options identifies the Classes and Objects?

    • A.

      Class: Real Chocos Private Limited Objects: Chocolate

    • B.

      Class: Chocolate Objects: Fruit Chocolates, Rum Chocolates, Milk Chocolates

    • C.

      Class: Choclate Objects: Milk Chocolates

    • D.

      Class: Fruit Chocolates Objects: Rum Chocolates

    Correct Answer
    B. Class: Chocolate Objects: Fruit Chocolates, Rum Chocolates, Milk Chocolates
    Explanation
    In this scenario, the correct answer is "Class: Chocolate Objects: Fruit Chocolates, Rum Chocolates, Milk Chocolates." This is because the class represents the general category of chocolates, while the objects represent the specific varieties of chocolates that the organization manufactures.

    Rate this question:

  • 12. 

    Consider the following code snippet: class Animal { String name; public boolean equals(Object o) { Animal a = (Animal) o; // Code Here } } class TestAnimal { public static void main(String args[]) { Animal a = new Animal(); a.name = "Dog"; Animal b = new Animal(); b.name = "dog"; System.out.println(a.equals(b)); } } Which of the following code snippets should be replaced for the comment line (//Code Here) in the above given code, to get the output as true?

    • A.

      Return this.name.equalsIgnoreCase(a.name);

    • B.

      Return this.name.equals(a.name);

    • C.

      Return super.equals(a);

    • D.

      Return this.name == a.name;

    • E.

      Return this.name.hashCode() == a.name.hashCode();

    Correct Answer
    A. Return this.name.equalsIgnoreCase(a.name);
    Explanation
    The correct answer is "return this.name.equalsIgnoreCase(a.name);" because it compares the names of the two Animal objects while ignoring the case sensitivity. This will return true if the names are equal, regardless of whether they are in uppercase or lowercase.

    Rate this question:

  • 13. 

    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.

      Throws ClassCastException at runtime

    • B.

      Prints: B

    • C.

      Compilation Error 'Cannot find the symbol'

    • D.

      Prints: A

    Correct Answer
    C. Compilation Error 'Cannot find the symbol'
    Explanation
    The code will produce a compilation error 'Cannot find the symbol' because the method `method()` in the `Code2` class does not have an overload that accepts an `Object` parameter. The only available overloads are `method(A a)` and `method(B b)`, so when trying to call `method(new Object())`, the compiler cannot find a suitable method to match the argument type.

    Rate this question:

  • 14. 

    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?

    • A.

      An exception is thrown at runtime

    • B.

      Planet!

    • C.

      The code runs with no output

    • D.

      Welcome!

    • E.

      Compilation fails

    Correct Answer
    D. Welcome!
    Explanation
    The output of the above program will be "Welcome!". This is because the main method creates an instance of the WelcomePlanet class and assigns it to the variable wp. Then, a new instance of the Earth class is created and assigned to the variable planet. The welcomePlanet method is called with the planet variable as the argument. Inside the welcomePlanet method, the first if statement checks if the planet is an instance of Earth, which it is. Therefore, the code inside the if statement is executed and "Welcome!" is printed to the console.

    Rate this question:

  • 15. 

    Consider the following code: public class Code13 { public static void main(String... args) { for(String s:args) System.out.print(s + ", "); System.out.println(args.length); } } Which of the following will be the output if the above code is attempted to compile and execute?

    • A.

      Program compiles successfully and prints the passed arguments as comma separated values and finally prints the length of the arguments-list

    • B.

      Runtime Error: NoSuchMethodError

    • C.

      Variable arguments cannot be used with enhanced for-loop

    • D.

      Compilation Error: var-args cannot be used as arguments for main() method

    Correct Answer
    A. Program compiles successfully and prints the passed arguments as comma separated values and finally prints the length of the arguments-list
    Explanation
    The code will compile successfully and print the passed arguments as comma-separated values. It will also print the length of the arguments list. This is because the code uses the enhanced for-loop to iterate over the arguments array and prints each argument followed by a comma. Finally, it prints the length of the arguments array using the length property.

    Rate this question:

  • 16. 

    Consider the following code: class UT1 { static byte m1() { final char c = 'u0001'; return c; } static byte m3(final char c) {return c;} public static void main(String[] args) { char c = 'u0003'; System.out.print(""+m1()+m3(c)); } } Which of the following gives the valid output of the above code?

    • A.

      Compile-time error

    • B.

      Prints: 13

    • C.

      Run-time error

    • D.

      Prints: 4

    • E.

      None of the listed options

    Correct Answer
    A. Compile-time error
    Explanation
    The code will result in a compile-time error because the method m1() is declared to return a byte, but it is actually returning a char. Since a char cannot be automatically converted to a byte, the code will fail to compile.

    Rate this question:

  • 17. 

    An Annotation Type ________________.

    • A.

      Is a meta-tag used to pass message between the code and JVM.

    • B.

      Defines the structure of an interface

    • C.

      Defines the structure of an Application

    • D.

      Defines the structure of an Object

    • E.

      Defines the structure of an Annotation

    Correct Answer
    E. Defines the structure of an Annotation
    Explanation
    An annotation type is used to define the structure of an annotation. Annotations are used to provide additional information about code elements, such as classes, methods, or fields. They can be used by the code or by the JVM to perform specific actions or make certain decisions at runtime. By defining the structure of an annotation using an annotation type, developers can specify what elements can be included in the annotation and what values they can have. This allows for more flexibility and control when using annotations in code.

    Rate this question:

  • 18. 

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

    • A.

      It improves performance

    • B.

      The numeric key is unique

    • C.

      It is a 32 bit numeric digest key

    • D.

      HashCode() is defined in String class

    • E.

      HashCode() value cannot be a zero-value

    Correct Answer(s)
    A. It improves performance
    C. It is a 32 bit numeric digest key
    Explanation
    The first correct statement is that HashCode improves performance. This is because HashCode is used in hashing algorithms to quickly locate objects in data structures like hash tables. By providing a unique numeric representation for each object, HashCode allows for efficient retrieval and storage of data.

    The second correct statement is that HashCode is a 32-bit numeric digest key. This means that the HashCode value is a 32-bit integer that represents a digest or summary of the object's data. This allows for efficient comparison and identification of objects based on their HashCode values.

    Rate this question:

  • 19. 

    Given the following object hierarchy and code for the upgrade method: java.lang.Object +----mypkg.BaseWidget | +----TypeAWidget // the following is a method in the BaseWidget class 1. public TypeAWidget upgrade( ){ 2. TypeAWidget A = (TypeAWidget) this; 3. return A; 4. } Which of the following will be the result of the below statements? 5. BaseWidget B = new BaseWidget(); 6. TypeAWidget A = B.upgrade();

    • A.

      The compiler would object to line 2.

    • B.

      A runtime ClassCastException would be generated in line 2.

    • C.

      As this referes to the BaseWidget, a parent can accept itschild

    • D.

      After line 6 executes, the object referred to as A will in factbe a TypeAWidget.

    Correct Answer
    B. A runtime ClassCastException would be generated in line 2.
    Explanation
    The code is trying to cast an object of type BaseWidget to TypeAWidget using the "upgrade" method. However, since the object B is an instance of BaseWidget and not TypeAWidget, a ClassCastException will be thrown at line 2, indicating that the casting is not possible.

    Rate this question:

  • 20. 

    Consider the following program: public class ThreadJoin extends Thread{ public static void main(String[] args) { Thread t1 = new Thread("T1"); Thread t2 = new Thread("T2"); try { t1.join(); t2.join(); } catch (InterruptedException e) { System.out.println("Main Thread interrupted."); } } public void run(){ System.out.println("Run executed"); } } What will be the output of the above program?

    • A.

      Run-time error

    • B.

      Compile-time error

    • C.

      Prints "Main Thread interrupted."

    • D.

      Program ends without printing anything

    • E.

      Prints "Run executed" twice

    Correct Answer
    D. Program ends without printing anything
    Explanation
    The program ends without printing anything because the main thread is calling the join() method on t1 and t2 threads without starting them. The join() method waits for the completion of the specified thread, but since the threads are not started, they never execute the run() method and the program ends without printing anything.

    Rate this question:

  • 21. 

    Which are all platform independent among the following? (Choose 3)

    • A.

      JAR Files

    • B.

      Java Virtual Machine (JVM)

    • C.

      Java Development Kit (JDK)

    • D.

      Java Class Files

    • E.

      Java Source Files

    Correct Answer(s)
    A. JAR Files
    D. Java Class Files
    E. Java Source Files
    Explanation
    JAR Files, Java Class Files, and Java Source Files are all platform independent. JAR Files are archives that contain compiled Java classes and resources, which can be executed on any platform that has a Java Virtual Machine (JVM). Java Class Files are compiled bytecode that can be executed on any platform with a JVM. Java Source Files are plain text files that contain Java code and can be compiled into Java Class Files, which are then executed on a JVM. Therefore, all three options can be run on multiple platforms without any modifications.

    Rate this question:

  • 22. 

    Which of the following options is true about multiple inheritance?

    • A.

      Inheriting from a class which is already in an inheritancehierarchy

    • B.

      Inheriting from more than one super class

    • C.

      Inheriting from two super classes

    • D.

      Inheriting from a single class

    Correct Answer
    B. Inheriting from more than one super class
    Explanation
    Multiple inheritance refers to the ability of a class to inherit attributes and behaviors from more than one superclass. In this case, the correct answer states that multiple inheritance involves inheriting from more than one super class. This means that a subclass can inherit characteristics from two or more different parent classes, allowing it to access and utilize the attributes and methods defined in each of those super classes.

    Rate this question:

  • 23. 

    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.

      List

    • B.

      SortedSet

    • C.

      Set

    • D.

      ArrayList

    • E.

      TreeSet

    Correct Answer(s)
    B. SortedSet
    E. TreeSet
    Explanation
    SortedSet and TreeSet are data structures that can be used for elements that have ordering but no duplicates. SortedSet is an interface in Java that extends the Set interface and maintains the elements in a sorted order. It does not allow duplicates. TreeSet is a class in Java that implements the SortedSet interface and internally uses a balanced tree structure to store the elements. It also maintains the elements in a sorted order and does not allow duplicates.

    Rate this question:

  • 24. 

    Which of the following options are true for StringBuffer class?(choose 3)

    • A.

      'capacity' property indicates the maximum number ofcharacters that a StringBuffer can have

    • B.

      StringBuffer is extended from String class

    • C.

      StringBuffer implements Charsequence interface

    • D.

      StringBuffer is threadsafe

    • E.

      Buffer space in StringBuffer can be shared

    Correct Answer(s)
    C. StringBuffer implements Charsequence interface
    D. StringBuffer is threadsafe
    E. Buffer space in StringBuffer can be shared
    Explanation
    The given answer is correct.


    1) StringBuffer implements the Charsequence interface, which means it can be used to represent a sequence of characters.
    2) StringBuffer is thread-safe, which means multiple threads can safely access and modify a StringBuffer object without causing any data corruption or inconsistency.
    3) The buffer space in a StringBuffer can be shared, allowing multiple strings to be appended or inserted into the same buffer without creating new objects. This can improve performance and memory efficiency.

    Rate this question:

  • 25. 

    Consider the following partial code: public class CreditCard { private String cardID; private Integer limit; public String ownerName; public void setCardInformation(String cardID, String ownerName, Integer limit) { this.cardID = cardID; this.ownerName = ownerName; this.limit = limit; } } Which of the following statement is True regarding the above given code?

    • A.

      The class is fully encapsulated

    • B.

      The setCardInformation method breaks encapsulation

    • C.

      The code demonstrates polymorphism

    • D.

      The cardID and limit variables break polymorphism

    • E.

      The ownerName variable breaks encapsulation

    Correct Answer
    E. The ownerName variable breaks encapsulation
    Explanation
    The ownerName variable breaks encapsulation because it is declared as public, allowing direct access to it from outside the class. Encapsulation refers to the practice of hiding internal data and implementation details of a class, and providing access to them through methods. By declaring the ownerName variable as public, it can be accessed and modified directly without going through any methods, which violates the principle of encapsulation.

    Rate this question:

  • 26. 

    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.

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

    • B.

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

    • C.

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

    • D.

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

    • E.

      Public void add(C c) { c.getValue(); }

    Correct Answer(s)
    B. Public void add(A a, B b) { a.getValue(); }
    C. Public void add(B b) { b.getValue(); }
    D. Public void add(A a) { a.getValue(); }
    Explanation
    The correct answer is "public void add(A a, B b) { a.getValue(); }, public void add(B b) { b.getValue(); }, public void add(A a) { a.getValue(); }". These code fragments make use of polymorphism because they accept objects of different classes (A, B, and C) as parameters, but they all call the getValue() method, which is defined in the interface A and implemented in the class B. This demonstrates polymorphism, as the same method can be called on objects of different classes that implement the same interface.

    Rate this question:

  • 27. 

    Consider the following program: import java.io.*; public class CrypticCatch { public static void main(String[] args) throws Exception { try { try { try { throw new FileNotFoundException(); } catch(Exception e3) { throw e3; } } catch(IOException e2) { throw e2; } } catch(FileNotFoundException e1) { System.out.println("File not found exception caught"); } System.out.println("Exception handled successfully"); } } What will be the output of the above program?

    • A.

      Runtime error

    • B.

      File not found exception caught

    • C.

      Compile time error. Since exceptions should be caught inreversed hierarchy order

    • D.

      Exception handled successfully

    • E.

      File not found exception caughtException handled successfully

    Correct Answer
    E. File not found exception caughtException handled successfully
    Explanation
    The output of the program will be "File not found exception caught" followed by "Exception handled successfully". This is because the program throws a FileNotFoundException in the innermost try block, which is then caught by the catch block for FileNotFoundException. The catch block prints "File not found exception caught". After that, the program continues to execute and prints "Exception handled successfully".

    Rate this question:

  • 28. 

    Which of the following annotations are defined in java.lang.annotation package? (Choose 2)

    • A.

      @Retention

    • B.

      @Deprecated

    • C.

      @Override

    • D.

      @SuppressWarnings

    • E.

      @Target

    Correct Answer(s)
    A. @Retention
    E. @Target
    Explanation
    The annotations @Retention and @Target are defined in the java.lang.annotation package. The @Retention annotation is used to specify how long an annotation should be retained, whether it should be available at runtime or only during compilation. The @Target annotation is used to specify the elements to which an annotation can be applied, such as classes, methods, or fields. Both of these annotations are commonly used in Java programming to provide additional information or metadata about code elements.

    Rate this question:

  • 29. 

    What are the new updations to java.io.File class in JDK 1.6?(Choose 2)

    • A.

      Methods to retrieve disk usage information

    • B.

      Methods to set or query file permissions

    • C.

      Methods to attach the file to an email

    • D.

      Methods to encrypt the file with password

    • E.

      No new methods are introduced in JDK 1.6

    Correct Answer(s)
    A. Methods to retrieve disk usage information
    B. Methods to set or query file permissions
    Explanation
    In JDK 1.6, two new updations were made to the java.io.File class. The first updation is the addition of methods to retrieve disk usage information. These methods allow the user to obtain information about the amount of disk space used by a file. The second updation is the addition of methods to set or query file permissions. These methods enable the user to manipulate and check the permissions associated with a file. No new methods were introduced in JDK 1.6 for attaching the file to an email or encrypting the file with a password.

    Rate this question:

  • 30. 

    Consider the following code: 1. public class DagRag { 2. public static void main(String [] args) { 3. 4. int [][] x = new int[2][4]; 5. 6. for(int y = 0; y < 2; y++) { 7. for(int z = 0; z < 4; z++) { 8. x[y][z] = z; 9. } 10. } 11. 12. dg: for(int g = 0; g < 2; g++) { 13. rg: for(int h = 0; h < 4; h++) { 14. System.out.println(x[g][h]); 15. 16. } 17. System.out.println("The end."); 18. 19. } 20. 21. } 22. } Which of the following code snippet when inserted at lines 15 and 18 respectively, will make the above program to generate the below output? 0 1 2 3 The end.

    • A.

      If(g==3) break rg;if(h==0) break dg;

    • B.

      If(h > 3) break dg;if(g > 0) break rg;

    • C.

      If(h==3) break rg;if(g==0) break dg;

    • D.

      If(h > 3) break dg;if(g > 0) break dg;

    Correct Answer
    C. If(h==3) break rg;if(g==0) break dg;
  • 31. 

    Consider the following code: public abstract class Shape { private int x; private int y; public abstract void draw(); public void setAnchor(int x, int y) { this.x = x; this.y = y; } } Which of the following implementations use the Shape class correctly? (Choose 2)

    • A.

      Public class Circle extends Shape {private int radius;public void setRadius(int radius) { this.radius = radius; }public int getRadius() { return radius; }public void draw() {/* code here */}}

    • B.

      Public class Circle implements Shape {private int radius;}

    • C.

      Public class Circle extends Shape {public int radius;private void draw() {/* code here */}}

    • D.

      Public abstract class Circle extends Shape {private int radius;}

    • E.

      Public class Circle extends Shape {private int radius;public void draw();}

    Correct Answer(s)
    A. Public class Circle extends Shape {private int radius;public void setRadius(int radius) { this.radius = radius; }public int getRadius() { return radius; }public void draw() {/* code here */}}
    D. Public abstract class Circle extends Shape {private int radius;}
    Explanation
    The first implementation correctly extends the Shape class and provides the necessary implementation for the draw() method. It also includes methods to set and get the radius of the Circle.

    The second implementation also correctly extends the Shape class but does not provide any additional implementation or methods specific to the Circle class. However, it still follows the correct structure and inheritance.

    Therefore, the first and second implementations use the Shape class correctly.

    Rate this question:

  • 32. 

    Consider the following code snippet: public class TestString9 { public static void main(String st[]){ String s1 = "java"; String s2 = "java"; String s3 = "JAVA"; s2.toUpperCase(); s3.toUpperCase(); boolean b1 = s1==s2; boolean b2 = s1==s3; System.out.print(b1); System.out.print(" "+b2); } } What will be the output of the above code snippet?

    • A.

      False true

    • B.

      True true

    • C.

      True false

    • D.

      Runtime error

    • E.

      False false

    Correct Answer
    C. True false
    Explanation
    The output of the above code snippet will be "true false". This is because the variables s2 and s3 are not actually modified by the toUpperCase() method. In Java, strings are immutable, meaning that their values cannot be changed once they are created. So when the toUpperCase() method is called on s2 and s3, it creates new strings with the uppercase versions of the original strings, but these new strings are not assigned to any variable. Therefore, the comparison of s1 with s2 will be true because they both refer to the same string "java", while the comparison of s1 with s3 will be false because they refer to different strings ("java" and "JAVA").

    Rate this question:

  • 33. 

    Consider the following code snippet: import java.io.*; public class IOCode2 { public static void main(String args[]) throws FileNotFoundException { // Insert Code here System.out.println("Welcome to File Programming"); } } Which of the following code snippets when substituted to the comment line (// Insert Code here), will redirect the output generated by the System.out.println() methods, in the above code?

    • A.

      System.out.setOut(new PrintStream("C:/Data"));

    • B.

      System.out.redirectOutput(new PrintStream("C:/Data"));

    • C.

      System.redirectOutput(new PrintStream("C:/Data"));

    • D.

      System.setOut(new PrintStream("C:/Data"));

    • E.

      System.setOut(new FileWriter("C:/Data"));

    Correct Answer
    D. System.setOut(new PrintStream("C:/Data"));
    Explanation
    The correct answer is System.setOut(new PrintStream("C:/Data")); This code snippet redirects the output generated by the System.out.println() method to the file "C:/Data" by setting the output stream to a new PrintStream object that is created with the file as its parameter.

    Rate this question:

  • 34. 

    Which of the following types of driver provides maximum decoupling between database and Java application?

    • A.

      Type II driver

    • B.

      Type III driver

    • C.

      Type I driver

    • D.

      Type IV driver

    Correct Answer
    B. Type III driver
    Explanation
    A Type III driver provides maximum decoupling between the database and Java application. This is because it uses a middleware server between the database and the application, allowing for easy migration between different databases without changing the application code. The middleware server translates the JDBC calls from the application into the specific database protocol, providing a high level of abstraction and flexibility. This driver is also known as the Network Protocol driver and is commonly used in web-based applications.

    Rate this question:

  • 35. 

    Consider the following code snippet: import java.util.*; class Student { String studentName; Student() { } Student(String studentName) { this.studentName = studentName; } public String toString() { return this.studentName; } } public class TestCol7 { public static void main(String args[]) { TreeSet students = new TreeSet(); students.add(new Student("Raju")); students.add(new Student("Krishna")); students.add(new Student("Vijay")); System.out.println(students); } } Running the above code, throws Runtime exception. Which of the following options will make the code run properly?

    • A.

      The Student class should implement Comparable interface.

    • B.

      The Student class should implement Cloneable interface

    • C.

      The Student class should implement Serializable interface

    • D.

      The Student class should implement Comparator interface.

    • E.

      The Student class should implement Externalizable interface

    Correct Answer
    A. The Student class should implement Comparable interface.
    Explanation
    The code snippet is using a TreeSet to store objects of the Student class. A TreeSet requires its elements to be comparable in order to maintain a sorted order. Therefore, the Student class should implement the Comparable interface and override the compareTo() method to define the natural ordering of Student objects based on their names. This will allow the TreeSet to properly sort and store the Student objects without throwing a runtime exception.

    Rate this question:

  • 36. 

    Consider the following code snippet: 1. class Garbage { } 2. class GC1 { 3. public static void main(String a[]) { 4. Garbage s = new Garbage(); 5. { 6. s = new Garbage(); 7. } 8. s = new Garbage(); 9. } 10. } Which of the following options gives the correct combination of lines that makes objects eligible for garbage Collection?

    • A.

      Lines: 4, 6

    • B.

      Lines: 4, 6, 8

    • C.

      None of the object is eligible for Garbage Collection

    • D.

      Lines: 6, 8

    • E.

      Lines: 8

    Correct Answer
    D. Lines: 6, 8
    Explanation
    In the given code snippet, an object of the class Garbage is created and assigned to the variable 's' at line 4. Then, a new object of Garbage is created and assigned to 's' within a block at line 6. This means that the object created at line 4 is no longer referenced and becomes eligible for garbage collection. Finally, at line 8, a new object of Garbage is created and assigned to 's' again, making the object created at line 6 also eligible for garbage collection. Therefore, the correct combination of lines that makes objects eligible for garbage collection is lines 6 and 8.

    Rate this question:

  • 37. 

    Which of the following options are true? (Choose 2)

    • A.

      The catch block can have another try-catch-finally block

    • B.

      In a try-catch-finally structure, finally block and catch blockcan be placed in any order

    • C.

      On using nested try-catch blocks, only the outer most trycatchblock can have the finally block

    • D.

      The finally block can have another try-catch-finally blocknested inside

    Correct Answer(s)
    A. The catch block can have another try-catch-finally block
    D. The finally block can have another try-catch-finally blocknested inside
    Explanation
    The catch block can have another try-catch-finally block because it is possible to handle exceptions within the catch block by placing another try-catch-finally structure inside it. This allows for further error handling and exception management. Similarly, the finally block can have another try-catch-finally block nested inside it, allowing for additional error handling and exception management within the finally block.

    Rate this question:

  • 38. 

    Consider the following program: public class TThread implements Runnable { public void run() { try { Thread.sleep(100000); } catch (Exception objE) { System.out.println ("Exception Handler"); } System.out.println ("Run method ends here"); } public static void main (String[] argv) { Thread thread = new Thread(new TThread ()); thread.start(); thread.interrupt(); System.out.println ("Main method ends here"); } } What will be the output of the above program?

    • A.

      None of the listed options

    • B.

      Exception Handler Run method ends here Main method ends here

    • C.

      Run method ends here Exception Handler Main method ends here

    • D.

      Main method ends here Run method ends here Exception Handler

    • E.

      Main method ends here Exception Handler Run method ends here

    Correct Answer
    C. Run method ends here Exception Handler Main method ends here
    Explanation
    The program creates a new thread and starts it. The new thread sleeps for 100000 milliseconds (100 seconds) and then prints "Run method ends here". Meanwhile, the main thread interrupts the new thread and prints "Main method ends here". Since the new thread is interrupted, it throws an InterruptedException and the catch block is executed, printing "Exception Handler". Therefore, the correct output is "Run method ends here Exception Handler Main method ends here".

    Rate this question:

  • 39. 

    Consider the following code: 1. class Test { 2. public static void main(String args[]) { 3. double d = 12.3; 4. Dec dec = new Dec(); 5. dec.dec(d); 6. System.out.println(d); 7. } 8. } 9. class Dec{ 10. public void dec(double d) { d = d - 2.0d; } 11. } Which of the following gives the correct value printed at line 6?

    • A.

      Prints: 12.3

    • B.

      Prints: -2.0

    • C.

      Prints: 10.3

    • D.

      Prints: 0.0

    Correct Answer
    A. Prints: 12.3
    Explanation
    The code creates an object of the Dec class and calls the dec() method on that object, passing in the value of the variable "d". Inside the dec() method, the value of "d" is subtracted by 2.0d, but this does not affect the value of the variable "d" in the main method. Therefore, when the value of "d" is printed at line 6, it is still the original value of 12.3.

    Rate this question:

  • 40. 

    Consider the following Statements: Statement A:The threads are scheduled using fixed priority scheduling. Statement B:Thread priority can be set after it is created using the public int setPriority() method declared in the Thread class. Which of the following statements is correct?

    • A.

      Both Statement A and B are true

    • B.

      Statement A is false and Statement B is true

    • C.

      Statement A is true and Statement B is false

    • D.

      Both Statement A and B are false

    Correct Answer
    C. Statement A is true and Statement B is false
    Explanation
    In this question, the correct answer is "Statement A is true and Statement B is false". This means that the threads are scheduled using fixed priority scheduling (Statement A is true), but the thread priority cannot be set after it is created using the public int setPriority() method declared in the Thread class (Statement B is false).

    Rate this question:

  • 41. 

    Consider the following code snippet: import java.util.*; public class TestCol4 { public static void main(String[] args) { Set h = new HashSet(); h.add("One"); h.add("Two"); h.add("Three"); h.add("Four"); h.add("One"); h.add("Four"); List l = new ArrayList(); l.add("One"); l.add("Two"); l.add("Three"); h.retainAll(l); System.out.println("Size:" + l.size() + h.size()); } } What will be the output of the above code snippet?

    • A.

      Size: 63

    • B.

      Size: 33

    • C.

      Size: 66

    • D.

      Compilation error

    • E.

      Size: 36

    Correct Answer
    A. Size: 63
    Explanation
    The output of the code snippet will be "Size: 63". The code snippet first creates a HashSet object "h" and adds six string elements to it. Then, it creates an ArrayList object "l" and adds three string elements to it. The "retainAll" method is called on the HashSet object "h" with the ArrayList object "l" as the argument. This method retains only the elements in "h" that are also present in "l". After that, the code snippet prints the size of "l" (which is 3) concatenated with the size of "h" (which is 6), resulting in "Size: 63".

    Rate this question:

  • 42. 

    Consider the following program: 1. class CheckedException extends RuntimeException { } 2. class UncheckedException extends Exception { } 3. public class Check { 4. public static void main(String args[]) { 5. generateException1(); 6. generateException2(); 7. } 8. 9. private static void generateException1() { 10. throw new CheckedException(); 11. } 12. 13. private static void generateException2() { 14. throw new UncheckedException(); 15. } 16. } Which of the following is true regarding the above given program?Compilation error at line 6

    • A.

      Compilation error at line 6

    • B.

      Compilation error at line 5

    • C.

      Compilation error at line 14

    • D.

      No compilation error but throws RuntimeException on running the code

    • E.

      Compilation error at line 10

    Correct Answer
    C. Compilation error at line 14
    Explanation
    The given program will result in a compilation error at line 14. This is because the method generateException2() is declared to throw an UncheckedException, which is a checked exception. However, the method does not have a try-catch block to handle the exception or a throws clause in its method signature. Therefore, the compiler will throw a compilation error at line 14.

    Rate this question:

  • 43. 

    Consider the following partial code: class Bean { interface I { void beanInterface(); } class BeanI extends Bean implements I { } } public class BeanImpl { public static void main(String args[]) { Bean bean = new Bean(); Bean.BeanI beanI = bean. new BeanI(); beanI.beanInterface(); } } Which of the following changes made to the class Bean without changing the class BeanImpl, will make the above code to compile properly?

    • A.

      The inner interface I should be removed and kept outside the Bean class

    • B.

      The inner class BeanI should be declared as abstract

    • C.

      The outer class Bean should be declared as abstract

    • D.

      Add the following method to Bean class public void beanInterface() { }

    • E.

      The inner class should be removed and kept outside the Bean class

    Correct Answer
    D. Add the following method to Bean class public void beanInterface() { }
    Explanation
    Adding the method "public void beanInterface() { }" to the Bean class will make the code compile properly because the BeanI class implements the I interface, which requires the implementation of the beanInterface() method. By adding this method to the Bean class, the BeanI class will have access to the implementation of the method and the code will compile without any errors.

    Rate this question:

  • 44. 

    Consider the following program: class UserDefinedException extends Error { } public class TasteIt { public static void main(String args[]) { try { try { throw new Error(); } catch(UserDefinedException u1) { throw u1; } catch(Exception e1) { System.out.println("This is the required output"); } finally { throw new UserDefinedException(); } } catch(UserDefinedException u2) { System.out.println("This is not the output"); } catch(Error e2) { System.out.println("This is the output"); } } } What will be the output for the above program?Runtime Error

    • A.

      Runtime Error

    • B.

      This is not the output

    • C.

      This is the output

    • D.

      This is the required output

    • E.

      Compile-time error

    Correct Answer
    B. This is not the output
    Explanation
    The output for the above program will be "This is the output". This is because the program throws an Error in the inner try block, but it is caught by the catch block for Exception. Therefore, the catch block for UserDefinedException is not executed. Finally, a UserDefinedException is thrown, but it is caught by the catch block for Error, which prints "This is the output".

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