![]() |
|
| #51 | Given Answer class behaves like some a File it has a Vector , a color, some boolean variable?
What is the correct declaration? | |
| Answer : ------------------------- | ||
| #52 | Some design issues: The following description applies to a class: given someclassname behaves as somesuperclassname and it has some fields etc it is accessed in other files. No other class can behave as this class.
What is the right syntax declaration of this class (without {)? | |
| Answer : ------------------------- | ||
| #53 | Which of the following is correct? Select the two correct answers. | |
| (1) | The native keyword indicates that the method is implemented in another language like C/C++ | |
| (2) | The only statements that can appear before an import statement in a Java file are comments | |
| (3) | The method definitions inside interfaces are public and abstract. They cannot be private or protected | |
| (4) | A class constructor may have public or protected keyword before them, nothing else | |
| Answer : ------------------------- | ||
| #54 | What is the result of compiling and running the following program.
| |
| (1) | abc | |
| (2) | def | |
| (3) | abcabc | |
| (4) | abcdef | |
| (5) | defabc | |
| (6) | abcdefdef | |
| Answer : ------------------------- | ||
| #55 | What is the result of compiling and running the following program. Select the one correct answer.
| |
| (1) | 'a' | |
| (2) | 'b' | |
| (3) | 'c' | |
| (4) | 'd' | |
| Answer : ------------------------- | ||
| #56 | To make a variable defined in a class accessible only to methods defined in the classes in same package, which of the following keyword should be used. Select the one correct answer | |
| (1) | By using the keyword package before the variable | |
| (2) | By using the keyword private before the variable | |
| (3) | By using the keyword protected before the variable | |
| (4) | By using the keyword public before the variable | |
| (5) | The variable should not be preceded by any of the above mentioned keywords | |
| Answer : ------------------------- | ||
| #57 | Which Listener interface must be implemented by a class responsible for handling mouse clicks on buttons? | |
| Answer : ------------------------- | ||
| #58 | Which of the following will output -4.0 | |
| (1) | System.out.println(Math.floor(-4.7)); | |
| (2) | System.out.println(Math.round(-4.7)); | |
| (3) | System.out.println(Math.ceil(-4.7)); | |
| (4) | System.out.println(Math.Min(-4.7)); | |
| Answer : ------------------------- | ||
| #59 | What is the result of the following operation?
| |
| (1) | 6 | |
| (2) | 0 | |
| (3) | 1 | |
| (4) | 7 | |
| Answer : ------------------------- | ||
| #60 | What will happen when you attempt to compile and run the following code?
| |
| (1) | It will compile and the run method will print out the increasing value of i | |
| (2) | It will compile and calling start will print out the increasing value of i | |
| (3) | The code will cause an error at compile time | |
| (4) | Compilation will cause an error because while cannot take a parameter of true | |
| Answer : ------------------------- | ||
| #61 | What will the following code print out?
| |
| (1) | 12 | |
| (2) | 012 | |
| (3) | 10 | |
| (4) | 10.0 | |
| Answer : ------------------------- | ||
| #62 | You need to create a class that will store a unique object elements. You do not need to sort these elements but they must be unique. What interface might be most suitable to meet this need? | |
| (1) | Set | |
| (2) | List | |
| (3) | Map | |
| (4) | Vector | |
| Answer : ------------------------- | ||
| #63 | You are concerned about that your program may attempt to use more memory than is available. To avoid this situation you want to ensure that the Java Virtual Machine will run its garbage collection just before you start a complex routine. What can you do to be certain that garbage collection will run when you want. | |
| (1) | You cannot be certain when garbage collection will run | |
| (2) | Use the Runtime.gc() method to force garbage collection | |
| (3) | Ensure that all the variables you require to be garbage collected are set to null | |
| (4) | Use the System.gc() method to force garbage collection | |
| Answer : ------------------------- | ||
| #64 | Which of the following most closely describes a bitset collection? | |
| (1) | A class that contains groups of unique sequences of bits | |
| (2) | A method for flipping individual bits in instance of a primitive type | |
| (3) | An array of boolean primitives that indicate zeros or ones | |
| (4) | A collection for storing bits as on-off information, like a vector of bits | |
| Answer : ------------------------- | ||
| #65 | You have these files in the same directory. What will happen when you attempt to compile and run Class1.java if you have not already compiled Base.java
| |
| (1) | Compile Error: Methods in Base not found | |
| (2) | Compile Error: Unable to access protected method in base class | |
| (3) | Compilation followed by the output "amethod" | |
| (4) | Compile error: Superclass Class1.Base of class Class1.Class1 not found | |
| Answer : ------------------------- | ||
| #66 | Given:
What is the result of attempting to compile and run the above program? | |
| (1) | Prints: v w x y | |
| (2) | Prints: v w x y z Default | |
| (3) | Prints: v y w z | |
| (4) | Prints: Default Default Default Default | |
| (5) | Runtime Exception | |
| (6) | Compiler Error | |
| (7) | None of the Above | |
| Answer : ------------------------- | ||
| #67 | Given:
What is the result of attempting to compile and run the above program? | |
| (1) | Prints: 12457 | |
| (2) | Prints: 02357 | |
| (3) | Prints: 02356 | |
| (4) | Prints: 1357 | |
| (5) | Prints: 1356 | |
| (6) | Runtime Exception | |
| (7) | Compiler Error | |
| (8) | None of the Above | |
| Answer : ------------------------- | ||
| #68 |
What is the result of attempting to compile the program? | |
| (1) | Compiler error at line 2 | |
| (2) | Compiler error at line 3 | |
| (3) | Compiler error at line 4 | |
| (4) | Compiler error at line 5 | |
| (5) | Compiler error at line 6 | |
| (6) | Compiler error at line 7 | |
| (7) | None of the Above | |
| Answer : ------------------------- | ||
| #69 |
What is the result of attempting to compile and run the program? | |
| (1) | Prints: 1,1,1,0,0,1 | |
| (2) | Prints: 0,1,1,0,0,1 | |
| (3) | Prints: 0,1,0,0,0,0 | |
| (4) | Prints: 0,1,0,0,0,1 | |
| (5) | Prints: 0,0,1,0,0,1 | |
| (6) | Compiler Error | |
| (7) | Run Time Error | |
| (8) | None of the Above | |
| Answer : ------------------------- | ||
| #70 |
What is the result of attempting to compile and run the above program? | |
| (1) | Prints: 1,2,3 | |
| (2) | Prints: 1,3,2 | |
| (3) | Prints: 2,2,2 | |
| (4) | Prints: 2,4,1 | |
| (5) | Prints: 2,4,2 | |
| (6) | Runtime Exception | |
| (7) | Compiler Error | |
| (8) | None of the Above | |
| Answer : ------------------------- | ||
| #71 | Which of the follow are true statements. | |
| (1) | A nested class is any class that is declared within the body of another class or interface | |
| (2) | A nested class can not be declared within the body of an interface declaration | |
| (3) | A top level class is a class this is not a nested class | |
| (4) | An inner class is a nested class that is not static | |
| (5) | A nested class can not be declared static | |
| (6) | A named class is any class that is not anonymous | |
| (7) | None of the above | |
| Answer : ------------------------- | ||
| #72 | The only access control modifiers supported by Java are:
| |
| (1) | True | |
| (2) | False | |
| Answer : ------------------------- | ||
| #73 | Which of the following are True? | |
| (1) | () is a unary operator | |
| (2) | () is a function operator | |
| (3) | int x = 10 + +11; is a invalid statment | |
| (4) | int x = (char)(int)(10); will give compiler error | |
| Answer : ------------------------- | ||
| #74 | Which of the following statements are False? | |
| (1) | Checked exceptions can not be caught using catch() in the same function | |
| (2) | New exception can be thrown with in a catch block | |
| (3) | No exception can be thrown from a finally block | |
| (4) | for loop executes its block statments atleast once | |
| (5) | Unhandled exceptions are handled by JVM and the program will coninue | |
| Answer : ------------------------- | ||
| #75 | What will happen if you compile/run this code?
| |
| (1) | Compilation error at line 7 | |
| (2) | Runtime exception at line 7 | |
| (3) | Prints "Before start method" and "After stop method" | |
| (4) | Prints "Before start method" only | |
| Answer : ------------------------- | ||
| #76 | The following code will give:
| |
| (1) | Compilation error at line 3 | |
| (2) | Compilation error at line 10 | |
| (3) | No compilation error, but runtime exception at line 3 | |
| (4) | No compilation error, but runtime exception at line 10 | |
| Answer : ------------------------- | ||
| #77 | The following code will print:
| |
| (1) | Compilation error | |
| (2) | No compilation error, but runtime exception | |
| (3) | Prints "True" | |
| (4) | Prints "False" | |
| Answer : ------------------------- | ||
| #78 | Which of the following statements are True? | |
| (1) | Constructors cannot have a visibility modifier | |
| (2) | Constructors can be marked public and protected, but not private | |
| (3) | Constructors can only have a primitive return type | |
| (4) | Constructors are not inherited | |
| Answer : ------------------------- | ||
| #79 | Which of the following will compile without error? | |
| (1) | char c='1'; System.out.println(c>>1); | |
| (2) | Integer i=Integer("1"); System.out.println(i>>1); | |
| (3) | int i=1; System.out.println(i<<<1); | |
| (4) | int i=1; System.out.println(i<<1); | |
| Answer : ------------------------- | ||
| #80 | You are given a class hierarchy with an instance of the class Dog. The class Dog is a child of mammal and the class Mammal is a child of the class Vertebrate. The class Vertebrate has a method called move which prints out the string "move". The class mammal overrides this method and prints out the string "walks". The class Dog overrides this method and prints out the string "walks on paws". Given an instance of the class Dog,. how can you access the ancestor method move in Vertebrate so it prints out the string "move"; | |
| (1) | d.super().super().move(); | |
| (2) | d.parent().parent().move(); | |
| (3) | d.move(); | |
| (4) | none of the above | |
| Answer : ------------------------- | ||
| #81 | Which of the following statements are True? | |
| (1) | An inner class may be defined as static | |
| (2) | There are NO circumstances where an inner class may be defined as private | |
| (3) | A programmer may only provide one constructor for an anonymous class | |
| (4) | An inner class may extend another class | |
| Answer : ------------------------- | ||
| #82 | Under what circumstances might you use the yield method of the Thread class | |
| (1) | To call from the currently running thread to allow another thread of the same or higher priority to run | |
| (2) | To call on a waiting thread to allow it to run | |
| (3) | To allow a thread of higher priority to run | |
| (4) | To call from the currently running thread with a parameter designating which thread should be allowed to run | |
| Answer : ------------------------- | ||
| #83 | What will be the result when you attempt to compile this program?
| |
| (1) | Compile time error referring to a cast problem | |
| (2) | A random number between 1 and 10 | |
| (3) | A random number between 0 and 1 | |
| (4) | A compile time error about random being an unrecognised method | |
| Answer : ------------------------- | ||
| #84 | It is possible for two classes to be the super class of each other. True Or False? | |
| (1) | True | |
| (2) | False | |
| Answer : ------------------------- | ||
| #85 | Given classes A, B & C where B extends A and C extends B, and where all classes implement the instance method 'void print()'. How can the print() method in A be called from an instance method in C? Select one right answer. | |
| (1) | print(); | |
| (2) | super.print(); | |
| (3) | super.super.print(); | |
| (4) | this.super.print(); | |
| (5) | A.this.print(); | |
| (6) | ((A)this).print(); | |
| (7) | It is not possible | |
| Answer : ------------------------- | ||
| #86 | Which of these statements are valid when occuring by themselves? Select all valid answers. | |
| (1) | while() break; | |
| (2) | do { break; } while (true); | |
| (3) | if (true) { break; } | |
| (4) | switch (1) { default: break; } | |
| (5) | for (;true;) break; | |
| Answer : ------------------------- | ||
| #87 | All public methods in the Thread class are static and therefore only affect the current thread. True Or False? | |
| (1) | True | |
| (2) | False | |
| Answer : ------------------------- | ||
| #88 | Which of the following statements regarding threads are true? Select all valid statements. | |
| (1) | void run(void) method is one of the methods in the Runnable interface | |
| (2) | yield() causes the current thread to move into the ready state | |
| (3) | some of the public methods in the Thread class are static | |
| (4) | notify() takes one argument, the object to which it needs to notify and notifyAll() takes no arguments | |
| (5) | every object has a lock which controls which thread has access to the objects synchronized code | |
| (6) | wait, notify & notifyAll methods must always be called from inside synchronized code | |
| (7) | wait, notify & notifyAll methods are part of Thread class only | |
| Answer : ------------------------- | ||
| #89 | The following code will print:
| |
| (1) | True True | |
| (2) | True False | |
| (3) | False True | |
| (4) | False False | |
| Answer : ------------------------- | ||
| #90 | What will happen if you compile/run the following code?
| |
| (1) | Duplicate method main(), compilation error at line 6 | |
| (2) | Duplicate method main(), compilation error at line 11 | |
| (3) | Prints "main method with main String[] args" | |
| (4) | Prints "main method with main int[] args" | |
| Answer : ------------------------- | ||
| #91 | What is the output of the following code?
| |
| (1) | Prints i >> 1 = 8 j >> 1 = 8 | |
| (2) | Prints i >> 1 = 7 j >> 1 = 7 | |
| (3) | Prints i >> 1 = 8 j >> 1 = 9 | |
| (4) | Prints i >> 1 = 7 j >> 1 = 8 | |
| Answer : ------------------------- | ||
| #92 | What is the output of the following code?
| |
| (1) | Compilation error at line 2. ~ operator applicable to boolean values only | |
| (2) | Prints 45677 | |
| (3) | Prints -45677 | |
| (4) | Prints -45679 | |
| Answer : ------------------------- | ||
| #93 | What will happen when you invoke the following method?
| |
| (1) | The loop never ends(infiniteLoop) | |
| (2) | Prints "Welcome to Java" | |
| (3) | Compilation error at line 5. ++ operator should not be used for byte type variables | |
| (4) | Prints nothing | |
| Answer : ------------------------- | ||
| #94 | Which of the following are syntactically correct? | |
| (1) | String[] sa1,sa2; | |
| (2) | Integer iwSize[] = new Integer[]{new Integer(1)}; | |
| (3) | short s[] = new short[10]; | |
| (4) | int i[10]; | |
| Answer : ------------------------- | ||
| #95 | Given the following code, which statement is true?
Select one right answer. | |
| (1) | The code will fail to compile owing to the line labeled (1) | |
| (2) | The code will throw a java.lang.ClassCastException at the line labelel (2), when run | |
| (3) | The code will throw a java.lang.ClassCastException at the line labelel (3), when run | |
| (4) | The code will compile and run without problems, even if the (B[]) cast in the lines labeled (2) & (3) were removed | |
| (5) | The code will compile and run without problems, but would not do so if the (B[]) cast in the lines (2) & (3) were removed | |
| Answer : ------------------------- | ||
| #96 | Given the following code
Which of the following statements are true? | |
| (1) | The hashCode method is correctly implemented | |
| (2) | This class will not compile as String has no hashCode method | |
| (3) | The hashCode method is not icorrectly implemented | |
| (4) | This class will not compile because the compareTo method is not implemented | |
| Answer : ------------------------- | ||
| #97 | Which of the following are methods of the Collection interface? | |
| (1) | iterator | |
| (2) | isEmpty | |
| (3) | toArray | |
| (4) | setText | |
| Answer : ------------------------- | ||
| #98 | What can cause a thread to stop executing? | |
| (1) | The program exits via a call to System.exit(0); | |
| (2) | Another thread is given a higher priority | |
| (3) | A call to the thread's stop method | |
| (4) | A call to the halt method of the Thread class | |
| Answer : ------------------------- | ||
| #99 | Given:
While one of the following statements is true? Select one correct answer. | |
| (1) | this.xyz is accessible from the main method with any access specifier for xyz | |
| (2) | this.xyz is accessible from the main method if the declaration of xyz is private | |
| (3) | this.xyz is accessible from the main method if the declaration of xyz is public | |
| (4) | This.xyz is accessible from the main method without any changes to the existing code | |
| Answer : ------------------------- | ||
| #100 | Which of the following statements are true? | |
| (1) | Creating a Thread using the Runnable interface does not require direct access to the Thread class | |
| (2) | Using the Thread class does not require any additional import statements | |
| (3) | yield is a static method of the Thread class | |
| (4) | yield is a static method of the Object class | |
| Answer : ------------------------- | ||