![]() |
|
| #201 | Given:
Which of the following constructor signatures MUST exist in the Demo class for Derived to compile correctly? | |
| (1) | public Demo(int a, int b) | |
| (2) | public Demo(int c) | |
| (3) | public Demo() | |
| Answer : ------------------------- | ||
| #202 | Which of the following class declarations for a normal top level class are incorrect? | |
| (1) | public synchronized class Base extends Thread | |
| (2) | private protected class Base | |
| (3) | public abstract class Base | |
| (4) | class Base extends Thread | |
| Answer : ------------------------- | ||
| #203 | The GenericFruit class declares the following method:public void setCalorieContent(float f) You are writing a class Apple to extend GenericFruit and wish to add methods which overload the method in GenericFruit. Select all of the following which would constitute legal declarations of overloading methods. | |
| (1) | protected float setCalorieContent(String s) | |
| (2) | protected void setCalorieContent(float x) | |
| (3) | public void setCalorieContent(double d) | |
| (4) | public void setCalorieContent(String s) throws NumberFormatException | |
| Answer : ------------------------- | ||
| #204 | Here is the hierarchy of Exceptions related to array index errors:
Suppose you had a method X which could throw both array index and string index exceptions. Assuming that X does not have any try-catch statements, which of the following statements are correct? | |
| (1) | The declaration for X must include "throws ArrayIndexOutOfBoundsException, StringIndexOutOfBoundsException" | |
| (2) | If a method calling X catches IndexOutOfBoundsException, both array and string index exceptions will be caught | |
| (3) | If the declaration for X includes "throws IndexOutOfBoundsException", any calling method must use a try-catch block | |
| (4) | The declaration for X does not have to mention exceptions | |
| Answer : ------------------------- | ||
| #205 | The following method is designed to convert an input string to a floating point number, while detecting a bad format. Assume that "factor" is correctly defined elsewhere.
Which of the following descriptions of the results of various inputs to the method are correct? | |
| (1) | Input = "0.1234". Result: factor = 0.1234, "Finally" is printed, true is returned | |
| (2) | Input = "0.1234". Result: factor = 0.1234, "Finally" is printed, false is returned | |
| (3) | Input = null. Result: factor = NaN, "Finally" is printed, false is returned | |
| (4) | Input = null. Result: factor unchanged, "Finally" is printed, NullPointerException is thrown | |
| Answer : ------------------------- | ||
| #206 | Given the following code fragment:
Choose all of the declarations of x which will not cause a compilation error. | |
| (1) | byte x = 100; | |
| (2) | short x = 200; | |
| (3) | int x = 300; | |
| (4) | long x = 400; | |
| Answer : ------------------------- | ||
| #207 | In the following code for a class in which methodA has an inner class.
Which variables would the statement in line 8 be able to use in place of XX? Check all that apply. | |
| (1) | int ID (line 2) | |
| (2) | String name (line 3) | |
| (3) | int nn (line 4) | |
| (4) | int serialN (line 5) | |
| Answer : ------------------------- | ||
| #208 | What happens when we attempt to compile and run the following code?
| |
| (1) | The program will compile and run, producing the output "N = -1" | |
| (2) | The program will compile and run, producing the output "N = 1" | |
| (3) | A run time ArithmeticException will be thrown | |
| (4) | The program will compile and run, producing the output "N = 0" | |
| Answer : ------------------------- | ||
| #209 | What will happen when you attempt to compile and run the following code? (Assume that the code is compiled and run with assertions enabled.)
| |
| (1) | It will print -10 | |
| (2) | It will result in Assertion Error showing the message -"The value must not be negative" | |
| (3) | The code will not compile | |
| (4) | None of these | |
| Answer : ------------------------- | ||
| #210 | What will happen when you attempt to compile and run the following code?
| |
| (1) | Compile-time error | |
| (2) | prints 1 | |
| (3) | prints 2 | |
| (4) | prints 3 | |
| (5) | prints 7 | |
| (6) | prints 8 | |
| Answer : ------------------------- | ||
| #211 | What will happen when you attempt to compile and run the following code?
| |
| (1) | 300 | |
| (2) | 240 | |
| (3) | 120 | |
| (4) | 180 | |
| (5) | Compilation error | |
| (6) | None of the above | |
| Answer : ------------------------- | ||
| #212 | What will be the result of executing the following code?
| |
| (1) | The code won't compile | |
| (2) | "Some things are true in this world" will be printed | |
| (3) | "Hey this won't compile" will be printed | |
| (4) | None of these | |
| Answer : ------------------------- | ||
| #213 | What will happen when you attempt to compile and run the following code?
| |
| (1) | Compile-time error | |
| (2) | Runtime error | |
| (3) | Prints : "I am true interface" followed by " I am true String" | |
| (4) | Prints : "I am false interface" followed by " I am false String" | |
| (5) | Prints : "I am true interface" followed by " I am false String" | |
| (6) | Prints : "I am false interface" followed by " I am true String" | |
| Answer : ------------------------- | ||
| #214 | What results from attempting to compile and run the following code?
| |
| (1) | prints: Value is - 9 | |
| (2) | prints: Value is - 5 | |
| (3) | Compilation error | |
| (4) | None of these | |
| Answer : ------------------------- | ||
| #215 | In the following pieces of code, A and D will compile without any error. True/False?
| |
| (1) | True | |
| (2) | False | |
| Answer : ------------------------- | ||
| #216 | Which of the following collection classes from java.util package are Thread safe? | |
| (1) | Vector | |
| (2) | ArrayList | |
| (3) | HashMap | |
| (4) | Hashtable | |
| Answer : ------------------------- | ||
| #217 | What will happen when you attempt to compile and run the following code?
| |
| (1) | Prints : MyThread: start() followed by MyRunnable:run() | |
| (2) | Prints : MyThread: run() followed by MyRunnable:start() | |
| (3) | Prints : MyThread: start() followed by MyRunnable:start() | |
| (4) | Prints : MyThread: run() followed by MyRunnable:run() | |
| (5) | Compile time error | |
| (6) | None of the above | |
| Answer : ------------------------- | ||
| #218 | What will be the result of executing the following code?
| |
| (1) | Compilation error at line 5 | |
| (2) | Compilation error at line 9 | |
| (3) | Runtime exception at line 11 | |
| (4) | None of these | |
| Answer : ------------------------- | ||
| #219 | What can cause a Thread to stop executing? | |
| (1) | Calling its own yield method | |
| (2) | Calling the yield method of another thread | |
| (3) | A call to the halt method of the Thread class | |
| (4) | Another thread is given higher priority | |
| Answer : ------------------------- | ||
| #220 | Which of the following statements are true? | |
| (1) | The keys of HashSet are not ordered | |
| (2) | The keys of LinkedHashSet are ordered | |
| (3) | The keys of LinkedHashSet are ordered but not sorted | |
| (4) | The keys of LinkedHashMap are sorted | |
| Answer : ------------------------- | ||
| #221 | Given:
How many objects are eligible for GC in the following code after d = null? | |
| (1) | 1 | |
| (2) | 2 | |
| (3) | 3 | |
| (4) | 4 | |
| Answer : ------------------------- | ||
| #222 | What, if anything, is wrong with the following code?
| |
| (1) | The class TestClass cannot be declared abstract | |
| (2) | The variable j cannot be declared transient | |
| (3) | The variable k cannot be declared synchronized | |
| (4) | The constructor TestClass( ) cannot be declared final | |
| (5) | The method f( ) cannot be declared static | |
| Answer : ------------------------- | ||
| #223 | Which of these classes have a comparator() method? Select 2 correct options. | |
| (1) | TreeSet | |
| (2) | HashMap | |
| (3) | TreeMap | |
| (4) | HashSet | |
| (5) | ArrayList | |
| Answer : ------------------------- | ||
| #224 | Assume that Thread 1 currently holds the lock for an object (obj) for which 4 other threads, Thread 2 to 5, are waiting. Now, Thread 1 want to release the lock but as the same time, it want Thread 3 to get the lock. How will you accomplish this? | |
| (1) | Call t3.resume() after releasing the lock | |
| (2) | Call t3.release() after releasing the lock | |
| (3) | Instead of releasing the lock, call t3.accuire(obj); | |
| (4) | Instead of releasing the lock, call t3.notify(obj); | |
| (5) | None of these | |
| Answer : ------------------------- | ||
| #225 | What will be output by the following code?
| |
| (1) | Value for i=1 value for j=1 | |
| (2) | Value for i=2 value for j=1 | |
| (3) | Value for i=2 value for j=2 | |
| (4) | Value for i=3 value for j=1 | |
| Answer : ------------------------- | ||
| #226 | What will be the result of attempting to compile and run the following program?
| |
| (1) | The progarm will fail to compile | |
| (2) | ClassCastException at runtime | |
| (3) | It will print 30, 20 | |
| (4) | It will print 30, 30 | |
| (5) | It will print 20, 20 | |
| Answer : ------------------------- | ||
| #227 | Consider the following lines of code: | |
| (1) | None of the 3 lines will compile | |
| (2) | All the 3 line will compile and print nulltrue, truenull and nullnull respectively | |
| (3) | Line 1 and 2 won't compile but line 3 will print nullnull | |
| (4) | Line 3 won't compile but line 1 and 2 will print nulltrue and truenull respectively | |
| (5) | None of the above | |
| Answer : ------------------------- | ||
| #228 | Which of the following are true about the "default" constructor? Select 2 correct options | |
| (1) | It is provided by the compiler only if the class does not define any constructor | |
| (2) | It initializes the instance members of the class | |
| (3) | It calls the default 'no-args' constructor of the super class | |
| (4) | It initializes instance as well as class fields of the class | |
| (5) | It is provided by the compiler if the class does not define a 'no- args' constructor | |
| Answer : ------------------------- | ||
| #229 | Which of these methods from the Collection interface return the value true if the collection object was actually modified by the call? Select 3 correct options | |
| (1) | add( ) | |
| (2) | retainAll( ) | |
| (3) | containsAll( ) | |
| (4) | contains( ) | |
| (5) | remove() | |
| Answer : ------------------------- | ||
| #230 | Following is not a valid comment:
| |
| (1) | True | |
| (2) | False | |
| Answer : ------------------------- | ||
| #231 | Which statements regarding the following code are correct?
Select 1 correct option | |
| (1) | This code won't compile | |
| (2) | Constructor for Outer is public | |
| (3) | Constructor for Outer is private | |
| (4) | Constructor for Inner is public | |
| (5) | Constructor for Inner is protected | |
| Answer : ------------------------- | ||
| #232 | Consider the following method:
What will it return if the method is called with the input "0.0" ? Select 1 correct option | |
| (1) | It won't even compile | |
| (2) | It will return 10.0 | |
| (3) | It will return Float.Nan | |
| (4) | It will return 0.0 | |
| (5) | None of the above | |
| Answer : ------------------------- | ||
| #233 | The following code snippet will not compile.
Assume that out1 and out2 have method signature: public void out1(); and public void out2(); | |
| (1) | True | |
| (2) | False | |
| Answer : ------------------------- | ||
| #234 | Giri has written the following class to prevent garbage collection of the objects of this class. Is he mistaken?
| |
| (1) | True | |
| (2) | False | |
| Answer : ------------------------- | ||
| #235 | What happens when you try to compile and run the following class:
Select 1 correct option | |
| (1) | It throws an OverFlowException | |
| (2) | It will print two same -ive numbers | |
| (3) | It will print two different -ive numbers | |
| (4) | It will print one -ive and one +ive number of same magnitude | |
| (5) | It will print one -ive and one +ive number of different magnitude | |
| Answer : ------------------------- | ||
| #236 | Consider the following code snippet:
Which of the following statements are true? Select 2 correct options | |
| (1) | If IOException gets thrown at line1, then the whole method will end up throwing SQLException | |
| (2) | If IOException gets thrown at line1, then the whole method will end up throwing CloneNotSupportedException | |
| (3) | If IOException gets thrown at line1, then the whole method will end up throwing InstantiationException() | |
| (4) | If no exception is thrown at line1, then the whole method will end up throwing CloneNotSupportedException | |
| (5) | If SQLException gets thrown at line1, then the whole method will end up throwing InstantiationException() | |
| Answer : ------------------------- | ||
| #237 | Consider the following class hierarchy:
(B1 and B2 are subclasses of A and C1, C2 are subclasses of B1) Assume that method public void m1(){ ... } is defined in all of these classes EXCEPT B1 and C1. Which of the following statements are correct? Select 1 correct option | |
| (1) | objectOfC1.m1(); will cause a compilation error | |
| (2) | objectOfC2.m1(); will cause A's m1() to be called | |
| (3) | objectOfC1.m1(); will cause A's m1() to be called | |
| (4) | objectOfB1.m1(); will cause an expection at runtime | |
| (5) | objectOfB2.m1(); will cause an expection at runtime | |
| Answer : ------------------------- | ||
| #238 | What classes can an inner class extend? (Provided that the class is visible and is not final) Select 1 correct option | |
| (1) | Only the encapsulating class | |
| (2) | Any top level class | |
| (3) | Any class | |
| (4) | It depends on whether the inner class is defined in a method or not | |
| (5) | None of the above | |
| Answer : ------------------------- | ||
| #239 | Which of the following statements are true? | |
| (1) | System.out.println( -1 >>> 2);will output a result larger than 10 | |
| (2) | System.out.println( -1 >>> 2); will output a positive number | |
| (3) | System.out.println( 2 >> 1); Will output the number 1 | |
| (4) | System.out.println( 1 <<< 2); will output the number 4 | |
| Answer : ------------------------- | ||
| #240 | Given the following class definition, which of the following statements would be legal after the comment //Here?
| |
| (1) | System.out.println(s); | |
| (2) | System.out.println(iOther); | |
| (3) | System.out.println(iam); | |
| (4) | System.out.println(iArgs); | |
| Answer : ------------------------- | ||
| #241 | Which statments regarding the following program are correct?
Select 1 correct option | |
| (1) | It'll not compile as run method cannot be overridden | |
| (2) | It'll print both "Hello" and "World" 5 times each | |
| (3) | It'll print both "Hello" and "World" 5 times each but they may be interspersed | |
| (4) | Total 5 words will be printed | |
| (5) | Either 5 "Hello" or 5 "world" will be printed | |
| Answer : ------------------------- | ||
| #242 | Consider following two classes:
What will be the output of compiling and running class B? Select 1 correct option | |
| (1) | It will print 10 | |
| (2) | It will print 20 | |
| (3) | It will not compile | |
| (4) | It will throw an exception at Run time | |
| (5) | None of the above | |
| Answer : ------------------------- | ||
| #243 | What will happen when you attempt to compile and run the following code with the command line "java hello there"
| |
| (1) | Compile time error | |
| (2) | Compilation and output of "hello" | |
| (3) | Compilation and output of "there" | |
| (4) | None of the above | |
| Answer : ------------------------- | ||
| #244 | Which of the following statements are true [Check all correct answers] | |
| (1) | Checked exceptions are derived directly from Exception | |
| (2) | Checked exceptions are derived directly from RuntimeException | |
| (3) | Unchecked exceptions are derived directly from Exception | |
| (4) | Unchecked exceptions are derived direclty from RuntimeException | |
| (5) | Exception and RuntimeException are both subclasses of Throwable | |
| Answer : ------------------------- | ||
| #245 | Which of the following keywords are valid when declaring a top level class? [Check all correct answers] | |
| (1) | private | |
| (2) | native | |
| (3) | final | |
| (4) | transient | |
| (5) | abstract | |
| Answer : ------------------------- | ||
| #246 | After the execution of the code-fragment below, what will be the values of a, b and c?
| |
| (1) | a: 2 b: 18 c: 8 | |
| (2) | a: 7 b: 12 c: 8 | |
| (3) | a: 7 b: 18 c: 8 | |
| (4) | a: 7 b: 18 c: 4 | |
| (5) | None of the above | |
| Answer : ------------------------- | ||
| #247 | What, if anything, is wrong with the following code?
Select 2 correct options | |
| (1) | The class TestClass cannot be declared abstract | |
| (2) | The variable j cannot be declared transient | |
| (3) | The variable k cannot be declared synchronized | |
| (4) | The constructor TestClass( ) cannot be declared final | |
| (5) | The method f( ) cannot be declared static | |
| Answer : ------------------------- | ||
| #248 | Which of the following statements are true? | |
| (1) | An object will be garbage collected when it becomes unreachable | |
| (2) | An object will be garbage collected if it has null assigned to it | |
| (3) | The finalize method will be run before an object is garbage collected | |
| (4) | Garbage collection assures that a program will never run out of memory | |
| Answer : ------------------------- | ||
| #249 | What will the following program print?Select 1 correct option | |
| (1) | 3, 4, 3 | |
| (2) | 3, 3, 3 | |
| (3) | 4, 3, 4 | |
| (4) | 4, 3, 3 | |
| (5) | It will not compile | |
| Answer : ------------------------- | ||
| #250 | Consider following two classes:
What will be the output of compiling and running class B? Select 1 correct option | |
| (1) | It will print 10 | |
| (2) | It will print 20 | |
| (3) | It will not compile | |
| (4) | It will throw an exception at Run time | |
| (5) | None of the above | |
| Answer : ------------------------- | ||