![]() |
|
| #1 | Given:
What is the result? | |
| (1) | Compilation succeeds | |
| (2) | Compilation fails because of an error on line 1 | |
| (3) | Compilation fails because of an error on line 3 | |
| (4) | Compilation fails because of an error on line 7 | |
| Answer : ------------------------- | ||
| #2 | Given:
The ClassA class can be compiled successfully by inserting one of three possible options on line 3. When inserted separately, which three will allow compilation to succeed? (Choose three.) | |
| (1) | int x = 6; | |
| (2) | short x = 3; | |
| (3) | char x = 'y'; | |
| (4) | long x = 354; | |
| (5) | boolean x = true; | |
| Answer : ------------------------- | ||
| #3 | Given:
Which statement is true? | |
| (1) | The NewGarb class will not compile | |
| (2) | The getIt() method must not be declared as static | |
| (3) | The NewGarb class compiles, but an exception is received because dg is not set to null | |
| (4) | The rg object is eligible for garbage collection after a call to the getIt() method has returned | |
| Answer : ------------------------- | ||
| #4 | Given:
Which two additions will individually allow compilation to succeed? (Choose two.) | |
| (1) | "char c;" placed on line 2 | |
| (2) | "char c;" placed on line 4 | |
| (3) | "char c = 'f';" placed on line 2 | |
| (4) | "char c = 'f';" placed on line 4 | |
| (5) | "static char c;" placed on line 2 | |
| (6) | "char c = new char();" placed on line 4 | |
| Answer : ------------------------- | ||
| #5 | Given:
What is the resulting value of t? | |
| (1) | 2 | |
| (2) | 4 | |
| (3) | 6 | |
| (4) | 7 | |
| Answer : ------------------------- | ||
| #6 | Given:
When inserted on line 10, which line will override the getType method, allowing compilation to succeed and the output "This is x"? | |
| (1) | public Char getType(String a, int b, char c) { | |
| (2) | public Char getType(int b, String a, char c) { | |
| (3) | public String getType(String a, int b, char c) { | |
| (4) | public String getType(int b, String a, char c) { | |
| Answer : ------------------------- | ||
| #7 | Given:
What is the result? | |
| (1) | Compilation fails because of an error on line 6 | |
| (2) | Compilation fails because of an error on line 11 | |
| (3) | Compilation fails because of errors on lines 7 and 8 | |
| (4) | Compilation succeeds and the program prints each value in the holdB array at the end of the "This is " line. Each value is printed two times before the program ends, and the values are not printed in sequential order | |
| (5) | Compilation succeeds & the prog. prints each val in the holdB array at the end of the "This is " line. Each val is printed in order from 1-10 & after the val 10 prints, it starts printing the vals 1-10 in order again | |
| Answer : ------------------------- | ||
| #8 | Given:
Which main method should you add to the Birthdays class to allow the program to compile and run with all defined fields properly displayed? | |
| (1) | public static void main(String args[]) { Frame.visible = true; } | |
| (2) | public static void main(String args[]) { Frame f = new Frame(); f.setVisible(true);} | |
| (3) | public static void main(String args[]) { Birthdays b = new Birthdays(); b.pack(); b.setVisible(true); } | |
| (4) | public static void main(String args[]) { Frame f = Birthdays.new Frame(); f.pack(); f.visible = true; } | |
| Answer : ------------------------- | ||
| #9 | Given:
Which line should you insert on line 6 to accomplish this? | |
| (1) | i[a] = ((int)Math.min(x[a])); | |
| (2) | i[a] = ((int)Math.max(x[a])); | |
| (3) | i[a] = ((int)Math.ceil(x[a])); | |
| (4) | i[a] = ((int)Math.floor(x[a])); | |
| Answer : ------------------------- | ||
| #10 | Which statement about the Map interface is true? | |
| (1) | Entries are placed in a Map using the values() method | |
| (2) | Entries are placed in a Map using the entrySet() method | |
| (3) | A key/value association is added to a Map using the put() method | |
| (4) | A key/value association is added to a Map using the putAll() method | |
| Answer : ------------------------- | ||
| #11 | Consider this class:
Which of the following methods would be legal if added (individually) at line 4? | |
| (1) | public int aMethod(int a, int b) { } | |
| (2) | public float aMethod(float a, float b) { } | |
| (3) | public float aMethod(float a, float b, int c) throws _Exception { } | |
| (4) | public float aMethod(float c, float d) { } | |
| (5) | private float aMethod(int a, int b, int c) { } | |
| Answer : ------------------------- | ||
| #12 | Consider these classes, defined in separate source files:
Which of the following methods would be legal (individually) at line 2 in class Test2? | |
| (1) | float aMethod(float a, float b) { } | |
| (2) | public int aMethod(int a, int b) throws Exception { } | |
| (3) | public float aMethod(float a, float b) throws _Exception { } | |
| (4) | public float aMethod(float p, float q) { } | |
| Answer : ------------------------- | ||
| #13 | You have been given a design document for a veterinary registration system for implementation in Java technology. It states:
Given that the Pet class has already been defined, which of the following fields would be appropriate for inclusion in the Cat class as members? | |
| (1) | Pet thePet; | |
| (2) | Date registered; | |
| (3) | Date vaccinationDue; | |
| (4) | Cat theCat; | |
| (5) | boolean neutered; | |
| (6) | String markings; | |
| Answer : ------------------------- | ||
| #14 | You have been given a design document for a veterinary registration system for implementation in Java. It states: "A pet has an owner, a registration date, and a vaccination-due date. A cat is a pet that has a flag indicating if it has been neutered, and a textual description of its markings." Given that the Pet class has already been defined and you expect the Cat class to be used freely throughout the application, how would you make the opening declaration of the Cat class, up to but not including the first opening brace? Use only these words and spaces: boolean, Cat, class, Date, extends, Object, Owner, Pet, private, protected, public, String. | |
| Answer : ------------------------- | ||
| #15 | Consider the following classes, declared in separate source files:
What output results when the main method of the class Sub is run? | |
| (1) | Value is 5 Value is 6 | |
| (2) | This value is 5 This value is 6 | |
| (3) | Value is 5 This value is 6 | |
| (4) | This value is 5 Value is 6 | |
| (5) | I was passed 5 I was passed 6 | |
| Answer : ------------------------- | ||
| #16 | Consider the following class definition:
Which of the following are legitimate calls to construct instances of the Test class? | |
| (1) | Test t = new Test(); | |
| (2) | Test t = new Test(1); | |
| (3) | Test t = new Test(1, 2); | |
| (4) | Test t = new Test(1, 2, 3); | |
| (5) | Test t = (new Base()).new Test(1); | |
| Answer : ------------------------- | ||
| #17 | Consider the following class definition:
Which of the following forms of constructor must exist explicitly in the definition of the Base class? | |
| (1) | Base() { } | |
| (2) | Base(int j) { } | |
| (3) | Base(int j, int k) { } | |
| (4) | Base(int j, int k, int l) { } | |
| Answer : ------------------------- | ||
| #18 | Which of the following statements are true? | |
| (1) | An inner class may be declared private | |
| (2) | An inner class may be declared static | |
| (3) | An inner class defined in a method should always be anonymous | |
| (4) | An inner class defined in a method can access all the method local variables | |
| (5) | Construction of an inner class may require an instance of the outer class | |
| Answer : ------------------------- | ||
| #19 | Consider the following definition:
Which variables may be referenced correctly at line 8? | |
| (1) | a | |
| (2) | b | |
| (3) | c | |
| (4) | d | |
| (5) | e | |
| Answer : ------------------------- | ||
| #20 | Which of the following statements are true? | |
| (1) | Given that Inner is a non-static class declared inside a public class Outer, and appropriate constructor forms are defined, an instance of Inner may be constructed like this:new Outer().new Inner() | |
| (2) | If an anonymous inner class inside the class Outer is defined to implement the interface ActionListener, it may be constructed like this:new Outer().new ActionListener() | |
| (3) | Given that Inner is a non-static class declared inside a public class Outer and appropriate constructor forms are defined, an instance of Inner may be constructed in a static method like this:new Inner() | |
| (4) | An anonymous class instance that implements the interface MyInterface may be constructed and returned from a method like this: 1. return new MyInterface(int x) { 2. int x; 3. public MyInterface(int x) { 4. this.x = x; 5. } 6. }; | |
| Answer : ------------------------- | ||
| #21 | Given:
When the processing of line 2 begins how many objects of type J that were created at line 1 are eligible for garbage collection? | |
| (1) | 0 | |
| (2) | 1 | |
| (3) | 4 | |
| (4) | 5 | |
| (5) | Can not be determined without more information | |
| (6) | Compiler error | |
| (7) | Run time error | |
| (8) | None of the above | |
| Answer : ------------------------- | ||
| #22 | What is the output of the following code when compiled and run? Select two correct answers
| |
| (1) | Prints 0,1,1 | |
| (2) | Error during compilation at line 3 | |
| (3) | Prints 0,0,1 | |
| (4) | Error during compilation at line 4 | |
| (5) | Error during compilation at line 5 | |
| Answer : ------------------------- | ||
| #23 | What is the output of the following code when compiled and run? Select one correct answer
| |
| (1) | Prints 3 | |
| (2) | Error during compilation at line 4 | |
| (3) | Error during compilation at line 5 | |
| (4) | Prints 11 | |
| (5) | Prints 0 | |
| Answer : ------------------------- | ||
| #24 | Select three correct statements: | |
| (1) | The garbage collection thread cannot outlive the last user thread | |
| (2) | The garbage collection can be forced by invoking System.gc(). | |
| (3) | The garbage collection thread is a non-deamon thread | |
| (4) | The finalize() method is invoked at most once by the JVM for any given object | |
| (5) | The finalize() method may resurrect the object upon which it has been invoked | |
| Answer : ------------------------- | ||
| #25 | What is the output of the following code when compiled and run? Select one correct answer.
| |
| (1) | Prints: In TechnoSampleSub | |
| (2) | Prints: In TechnoSample | |
| (3) | Prints:
In TechnoSample
In TechnoSampleSub
| |
| (4) | Prints:
In TechnoSampleSub
In TechnoSample
| |
| (5) | The code does not compile | |
| Answer : ------------------------- | ||
| #26 | What is the output of the following code when compiled and run with the following command line: java TechnoSample two three? Select two correct answers.
| |
| (1) | The exception message is Values are:false,3,true | |
| (2) | The exception message is Values are:true,2,false | |
| (3) | The exception message is Values are:false,2,true | |
| (4) | The final value of b is false | |
| (5) | An exception is thrown at runtime | |
| Answer : ------------------------- | ||
| #27 | Select two correct statements about the code given below?
| |
| (1) | The code compiles without error and runs fine | |
| (2) | Compilation error on line 1 because interface E is not yet declared (forward-referencing) | |
| (3) | Compilation error on line 4 because class A does not implement interface E | |
| (4) | The cast on line 4 is mandatory | |
| (5) | The cast on line 5 is not mandatory | |
| Answer : ------------------------- | ||
| #28 | How many objects are eligible for garbage collection immediately after line 1? Select one correct answer.
| |
| (1) | 0 | |
| (2) | 1 | |
| (3) | 2 | |
| (4) | 3 | |
| (5) | 4 | |
| Answer : ------------------------- | ||
| #29 | What is the output of the following code when compiled and run? Select one correct answer.
| |
| (1) | The output cannot be determined | |
| (2) | Compilation error | |
| (3) | An exception is thrown at runtime | |
| (4) | Output is i = 2 | |
| (5) | Output is i > 5 (i=6) | |
| Answer : ------------------------- | ||
| #30 | What is the output of the following code when compiled and run? Select one correct answer.
| |
| (1) | Prints 0 1 2 3 4 | |
| (2) | Compilation error | |
| (3) | No output | |
| (4) | IllegalThreadStateException is thrown at runtime | |
| (5) | Prints 0 1 2 3 4 5 | |
| Answer : ------------------------- | ||
| #31 | What is the output of the following code when compiled and run? Select one correct answer.
| |
| (1) | Prints
Hello World
Hello World | |
| (2) | Prints
Hello orld
Hello orld | |
| (3) | Prints
Hello orld
ello orld | |
| (4) | Prints
ello orld
ello orld | |
| (5) | Compilation error | |
| Answer : ------------------------- | ||
| #32 | What is the output of the following code when compiled and run? Select two correct answers. (Note: when an instance of a Vector is printed, its content appear between square brackets [])
| |
| (1) | Compilation error on line 1 | |
| (2) | Only line 1 won't compile | |
| (3) | The code compiles and runs fine | |
| (4) | Prints [3.2, 2, 3.2, 2] | |
| (5) | Prints [1, 2, 3.2, 2] | |
| Answer : ------------------------- | ||
| #33 | What is the output of the following code when compiled and run? ('\u0048' is 'H' and '\u000a' is a linefeed (LF)). Select two correct answers.
| |
| (1) | Prints:
Hello
World!
| |
| (2) | Prints Hello World!(linefeed is ignored) | |
| (3) | Compilation error | |
| (4) | Compiles fine, but an exception is thrown at runtime | |
| (5) | Unicode characters like '\u0048' may be used to create String literals | |
| Answer : ------------------------- | ||
| #34 | What is the output of the following code when compiled and run? Select two correct answers.
| |
| (1) | Compilation error | |
| (2) | No arithmetic exception will never be printed | |
| (3) | The final value of i is 2 | |
| (4) | The final value of i is 0 | |
| (5) | The try-catch block is necessary for the code to compile | |
| Answer : ------------------------- | ||
| #35 | What is the output of the following code when compiled and run? Select two correct answers.
| |
| (1) | The output will always be the same whatever the underlying platform is | |
| (2) | Prints: End | |
| (3) | Prints:
0 1 2
End
| |
| (4) | The output cannot be determined | |
| (5) | Compilation error | |
| Answer : ------------------------- | ||
| #36 | What is the output of the following code when compiled and run? Select two correct answers.
| |
| (1) | Compilation error on line 1 | |
| (2) | Compilation error on line 2 | |
| (3) | Compilation error on line 3 | |
| (4) | Line 3 compiles fine | |
| (5) | Prints 10 random numbers between 0 and 127 | |
| Answer : ------------------------- | ||
| #37 | Select three correct statements. | |
| (1) | A static method may override another static method | |
| (2) | A static method cannot override a non-static method | |
| (3) | A non-static method cannot override a static method | |
| (4) | A non-static method may be overloaded by a static method | |
| (5) | A synchronized method cannot be overridden | |
| Answer : ------------------------- | ||
| #38 | Select three correct statements about the following code.
| |
| (1) | The try-catch block that encloses myref.test(); is mandatory for the code to compile | |
| (2) | Prints: In TechnoSample | |
| (3) | Prints: In TechnoSampleSub | |
| (4) | Method test() in class TechnoSampleSub has no obligation to declare a throws clause | |
| (5) | An exception is thrown at runtime | |
| Answer : ------------------------- | ||
| #39 | Given the following code:
Which one or more of the following correctly describe the behavior when this program is compiled and run? | |
| (1) | compilation is successful and the output is:d1 is Fri December 31 00:00:00 GMT 1999 d2 is Fri December 31 00:00:00 GMT 1999 | |
| (2) | compilation is successful and the output is:d1 is Fri December 31 00:00:00 GMT 1999 d2 is Sun December 31 00:00:00 GMT 2000 | |
| (3) | compilation is successful and the output is:d1 is Sun December 31 00:00:00 GMT 2000 d2 is Sun December 31 00:00:00 GMT 2000 | |
| (4) | the assignment 'd1 = d2' is rejected by the compiler because the Date class cannot overload the operator '=' | |
| (5) | the expression (d1 is " + d1 + "\nd2 is " + d2) is rejected by the compiler because the Date class cannot overload the operator '+' | |
| Answer : ------------------------- | ||
| #40 | Read this piece of code carefully
| |
| (1) | the code will compile an print "Equal" | |
| (2) | the code will compile an print "Not Equal" | |
| (3) | the code will cause a compiler error | |
| Answer : ------------------------- | ||
| #41 | Given the following code
Which of the following if placed after the comment //Here, will compile and modify the value of the variable oak? | |
| (1) | super.oak = 1; | |
| (2) | oak = 33; | |
| (3) | Base.oak = 22; | |
| (4) | oak = 50.1; | |
| Answer : ------------------------- | ||
| #42 | What will happen when you attempt to compile and run the following code?
| |
| (1) | Compile time error | |
| (2) | Output of 2 | |
| (3) | Output of 1 | |
| (4) | Output of 0 | |
| Answer : ------------------------- | ||
| #43 | Given the following class
Which of the following lines if placed after the comment //Here will print out 0. | |
| (1) | System.out.println(i++); | |
| (2) | System.out.println(i+'0'); | |
| (3) | System.out.println(i); | |
| (4) | System.out.println(i--); | |
| Answer : ------------------------- | ||
| #44 | What will happen when you attempt to compile and run this code?
| |
| (1) | Compile time error: Base cannot be private | |
| (2) | Compile time error indicating that an integer cannot be transient | |
| (3) | Compile time error transient not a data type | |
| (4) | Compile time error malformed main method | |
| Answer : ------------------------- | ||
| #45 | What best describes the appearance of an application with the following code?
| |
| (1) | A Frame with buttons marked One to Four placed on each edge | |
| (2) | A Frame with buutons marked One to four running from the top to bottom | |
| (3) | A Frame with one large button marked Four in the Centre | |
| (4) | An Error at run time indicating you have not set a LayoutManager | |
| Answer : ------------------------- | ||
| #46 | What will happen when you attempt to compile and run the following code?
| |
| (1) | A compile time error indicating that no run method is defined for the Thread class | |
| (2) | A run time error indicating that no run method is defined for the Thread class | |
| (3) | Clean compile and at run time the values 0 to 9 are printed out | |
| (4) | Clean compile but no output at runtime | |
| Answer : ------------------------- | ||
| #47 |
| |
| (1) | Compilation error, attempting to perform binary comparison on logical data type | |
| (2) | Compilation and output of "We are equal 10" | |
| (3) | Compilation and output of "Not equal! 20" | |
| (4) | Compilation and output of "Not equal! 10" | |
| Answer : ------------------------- | ||
| #48 | Given the following code, what will be the output?
| |
| (1) | 15 0 | |
| (2) | 15 0 | |
| (3) | 20 0 | |
| (4) | 0 15 | |
| Answer : ------------------------- | ||
| #49 | Given the code below, and making no other changes, which access modifiers (public, protected or private) can legally be placed before myMethod() on line 3? If line 3 is left as it is, which keywords can legally be placed before myMethod on line 8?
| |
| (1) | private or nothing (i.e. leaving it as it is) on line 3. Nothing (i.e. leaving it as it is) or protected or public on line 8 | |
| (2) | public or protected on line 3. private or nothing (i.e. leaving it as it is) on line 8 | |
| (3) | nothing (i.e. leaving it as it is) or protected or public on line 3. private or nothing (i.e. leaving it as it is) on line 8 | |
| (4) | None of the above | |
| Answer : ------------------------- | ||
| #50 | What is the result when you compile and run the following code?
| |
| (1) | Compilation error | |
| (2) | Runtime error | |
| (3) | Compile successfully, nothing is printed | |
| (4) | Inside throwMethod. followed by caught: java.lang.IllegalAccessExcption: demo | |
| Answer : ------------------------- | ||