Q 1:Which colour is used to indicate instance methods in the standard "javadoc" format documentation: [A] blue [B] red
[C] purple [D] orange Ans: B Q 2:What is the correct ordering for the import, class and package declarations when found in a single file? [A] package, import, class [B] class, import, package [C] import, package, class [D] package, class, import Ans: A Q 3:Which methods can be legally applied to a string object? [A] equals(String) [B] equals(Object) [C] trim() [D] toString() Ans: A,B,C,D Q 4:What is the parameter specification for the public static void main method? [A] String args [] [B] String [] args [C] Strings args [] [D] String args Ans: A,B Q 5:What does the zeroth element of the string array passed to the public static void main method contain? [A] The name of the program [B] The number of arguments [C] The first argument if one is present [D] None of these Ans: C Q 6:Which of the following are Java keywords? [A] goto [B] malloc [C] extends [D] FALSE Ans: A,C Q 7:What will be the result of compiling the following code: public class Test { 	public static void main (String args []) { 		int age; 		age = age + 1; 		[Link]("The age is " + age); 	} } [A] [B] [C] [D] Compiles Compiles Compiles Does not and runs with no output and runs printing out The age is 1 but generates a runtime error compile
Ans: D Q 8:Which of these is the correct format to use to create the literal char value a? [A] a [B] "a" [C] new Character(a) [D] \000a Ans: A Q 9:What is the legal range of a byte integral type? [A] 0 - 65, 535 [B] (-128) - 127 [C] (-32,768) - 32,767 [D] (-256) - 255 Ans: B Q 10:Which of the following is illegal: [A] int i = 32; [B] float f = 45.0; [C] double d = 45.0; [D] float f = 15.0ff; Ans: B,D Q 11:What will be the result of compiling the following code: public class Test { 	static int age; 	public static void main (String args []) { 		age = age + 1; 		[Link]("The age is " + age); 	} } [A] Compiles [B] Compiles [C] Compiles [D] Does not Ans: B and runs with no output and runs printing out The age is 1 but generates a runtime error compile
Q 12:Which of the following are correct? [A] 128 >> 1 gives 64 [B] 128 >>> 1 gives 64 [C] 128 >> 1 gives 64 [D] 128 >>> 1 gives -64 Ans: A,B Q 13:Which of the following return true? [A] "john" == "john" [B] "john".equals("john") [C] "john" = "john" [D] "john".equals(new Button("john")) Ans: A,B Q 14:Which of the following do not lead to a runtime error? [A] "john" + " was " + " here" [B] "john" + 3 [C] 3 + 5 [D] 5 + 5.5 Ans: A,B,C,D
Q 15:Which of the following are so called "short circuit" logical operators? [A] & [B] || [C] && [D] | Ans: B,C Q 16:Which of the following are acceptable? [A] Object o = new Button("A"); [B] Boolean flag = true; [C] Frame f = new Panel(); [D] Panel p = new Applet(); Ans: A,D Q 17:What is the result of compiling and running the following code: public class Test { 	static int total = 10; 	public static void main (String args []) { 		new Test(); 	} 	public Test () { 		[Link]("In test"); 		[Link](this); 		int temp = [Link]; 		if (temp > 5) { 		 [Link](temp); 		} 	} } [A] The [B] The [C] The [D] The Ans: C class will not compile compiler reports and error at line 2 value 10 is one of the elements printed to the standard output class compiles but generates a runtime error of the following is correct: temp [] = new String {"j" "a" "z"}; temp [] = { "j " " b" "c"}; temp = {"a", "b", "c"}; temp [] = {"a", "b", "c"};
Q 18:Which [A] String [B] String [C] String [D] String Ans: D
Q 19:What is the correct declaration of an abstract method that is intended to b e public: [A] public abstract void add(); [B] public abstract void add() {} [C] public abstract add(); [D] public virtual add(); Ans: A Q 20:Under what situations do you obtain a default constructor? [A] When you define any class [B] When the class has no other constructors [C] When you define at least one constructor [D] None of these Ans: B Q 21:Given the following code:
public class Test { } Which of the following can be used to define a constructor for this class: [A] public void Test() {...} [B] public Test() {...} [C] public static Test() {...} [D] public static void Test() {...} Ans: B Q 22:Which of the following are acceptable to the Java compiler: [A] if (2 == 3) [Link]("Hi"); [B] if (2 = 3) [Link]("Hi"); [C] if (true) [Link]("Hi"); [D] if ([Link]("hello")) [Link]("Hi"); Ans: A,C,D Q 23:Assuming a method contains code which may raise an Exception (but not a Run timeException), what is the correct way for a method to indicate that it expects the caller to h andle that exception: [A] throw Exception [B] throws Exception [C] new Exception [D] Don't need to specify anything Ans: B Q 24:What is the result of executing the following code, using the parameters 4 and 0: public void divide(int a, int b) { 	try { 		int c = a / b; 	} catch (Exception e) { 		[Link]("Exception "); 	} finally { 		[Link]("Finally"); } [A] Prints out: Exception Finally [B] Prints out: Finally [C] Prints out: Exception [D] No output Ans: A Q 25:Which of the following is a legal return type of a method overloading the f ollowing method: public void add(int a) {...} [A] void [B] int [C] Can be anything [D] None of these Ans: C Q 26:Which of the following statements is correct for a method which is overridi ng the following method: public void add(int a) {...} [A] the overriding method must return void [B] the overriding method must return int [C] the overriding method can return whatever it likes [D] None of these Ans: A Q 27:Which is true about a method-local inner class?
[A] It [B] It [C] It [D] It Ans: B
must be marked final. can be marked abstract. can be marked public. can be marked static.
Q 28:Where in a constructor, can you place a call to a constructor defined in th e super class? [A] Anywhere [B] The first statement in the constructor [C] The last statement in the constructor [D] You can't call super in a constructor Ans: B Q 29:Which variables can an inner class access from the class which encapsulates it? [A] All static variables [B] All final variables [C] Only final instance variables [D] All instance variables Ans: A,B,D Q 30:What class must an inner class extend: [A] The top level class [B] The Object class [C] Any class or interface [D] It must extend an interface Ans: C Q 31:In the following code, which is the earliest statement, where the object originally held in e, may be garbage collected: 1. public class Test { 2. public static void main (String args []) { 3. Employee e = new Employee("Bob", 48); 4. [Link](); 5. [Link]([Link]()); 6. e = null; 7. e = new Employee("Denise", 36); 8. [Link](); 9. [Link]([Link]()); 10. } 11. } [A] Line 10 [B] Line 11 [C] Line 7 [D] Line 8 Ans: C Q 32:Which constructs an anonymous inner class instance? [A] Runnable r = new Runnable() { }; [B] Runnable r = new Runnable(public void run() { }); [C] Runnable r = new Runnable { public void run(){}}; [D] [Link](new Runnable() {public void run() { }}); Ans: D Q 33:What is the name of the method used to schedule a thread for execution? [A] init(); [B] start(); [C] run(); [D] resume();
Ans: B Q 34:Which methods may cause a thread to stop executing? [A] sleep(); [B] stop(); [C] wait(); [D] yield(); Ans: A,B,C,D Q 35:Which statement is true about a static nested class? [A] You must have a reference to an instance of the enclosing class in order to instantiate it. [B] You must have a reference to an instance of the enclosing class in order to instantiate it. [C] It's variables and methods must be static. [D] It must extend the enclosing class. Ans: B Q 36:Which of the following methods are defined on the Graphics class: [A] drawLine(int, int, int, int) [B] drawImage(Image, int, int, ImageObserver) [C] add(Component); [D] setLayout(Object); Ans: A,B Q 37:Which of the following layout managers honours the preferred size of a comp onent: [A] CardLayout [B] FlowLayout [C] BorderLayout [D] GridLayout Ans: B Q 38:Which two of the following methods are defined in class Thread? [A] start() [B] wait() [C] notify() [D] run() Ans: A,D Q 39:Given the following code what is the effect of a being 5: public class Test { 	public void add(int a) { 	 loop: for (int i = 1; i < 3; i++){ 	 for (int j = 1; j < 3; j++) { 	 if (a == 5) { 	 break loop; 	 } 	 [Link](i * j); 	 } 	 } 	} } [A] Generate a runtime error [B] Throw an ArrayIndexOutOfBoundsException [C] Print the values: 1, 2, 2, 4 [D] Produces no output Ans: D Q 40:Given that a Button can generate an ActionEvent which listener would you ex
pect to have to implement, in a class which would handle this event? [A] FocusListener [B] ComponentListener [C] WindowListener [D] ActionListener Ans: D Q 41:Which of the following, are valid return types, for listener methods: [A] boolean [B] the type of event handled [C] void [D] Component Ans: C Q 42:What's the difference between servlets and applets? [Link] executes on Servers, where as Applets executes on Browser [Link] have no GUI, where as an Applet has GUI [Link] creates static web pages, where as Applets creates dynamic web pages [Link] can handle only a single request, where as Applet can handle multiple requests [A] 1,2,3 are correct [B] 1,2 are correct [C] 1,3 are correct [D] 1,2,3,4 are correct Ans: B Q 43:What is the permanent effect on the file system of writing data to a new Fi leWriter("report"), given the file report already exists? [A] The data is appended to the file [B] The file is replaced with a new file [C] An exception is raised as the file already exists [D] The data is written to random locations within the file Ans: B Q 44:Which of the following correctly illustrate how an InputStreamReader can be created: [A] new InputStreamReader(new FileInputStream("data")); [B] new InputStreamReader(new FileReader("data")); [C] new InputStreamReader(new BufferedReader("data")); [D] new InputStreamReader([Link]); Ans: A,D Q 45:Which of the following are Java keywords? [A] array [B] boolean [C] Integer [D] super Ans: B,D Q 46:Which identifiers are valid? [A] _xpoints [B] r2d2 [C] bBb$ [D] set-flow Ans: A,B,C Q 47:Which of the following statements assigns "Hello Java" to the String variab
le s? [A] String s = [B] String s[] [C] String s = [D] new String Ans: A,C
"Hello Java"; = "Hello Java"; new String("Hello Java"); s = "Hello Java";
Q 48:Given the variable declarations below: byte myByte; int myInt; long myLong; char myChar; float myFloat; double myDouble; Which one of the following assignments would need an explicit cast? [A] myInt = myByte; [B] myInt = myLong; [C] myByte = 3; [D] myFloat = myDouble; Ans: B,D Q 49:What is the effect ollowing manner: new Vector(5, 10); [A] An IndexOutOfBounds [B] The vector grows in [C] The vector grows in [D] Nothing, the vector Ans: C of adding the sixth element to a vector created in the f exception size to a size to a will have is raised. capacity of 10 elements capacity of 15 elements grown when the fifth element was added
Q 50:To declare an array of 31 floating point numbers representing snowfall for each day of March in Gnome, Alaska, which declarations would be valid? [A] double snow[] = new double[31]; [B] double snow[31] = new array[31]; [C] double snow[] = new double[31]; [D] double[] snow = new double[31]; Ans: C,D Q 51:Which of the following is a legal way to construct a RandomAccessFile: [A] RandomAccessFile("data", "r"); [B] RandomAccessFile("r", "data"); [C] RandomAccessFile("data", "read"); [D] RandomAccessFile("read", "data"); Ans: A Q 52:Given the following sequence of Java statements 1. StringBuffer sb = new StringBuffer("abc"); 2. String s = new String("abc"); 3. [Link]("def"); 4. [Link]("def"); 5. [Link](1, "zzz"); 6. [Link](sb); 7. [Link](); Which of the following statements are true: [A] The compiler would generate an error for line 3. [B] The compiler would generate an error for line 4. [C] The compiler would generate an error for line 6. [D] The compiler would generate an error for line 7. Ans: B,C
Q 53:What is the result of executing the following code when the value of x is 2 : switch (x) { case 1: [Link](1); case 2: case 3: [Link](3); case 4: [Link](4); } [A] Nothing is printed out [B] The value 3 is printed out [C] The values 3 and 4 are printed out [D] The values 1, 3 and 4 are printed out Ans: C Q 54:What is the result of executing the following fragment of code: boolean flag = false; if (flag = true) { [Link]("true"); } else { [Link]("false"); } [A] true is printed to standard out [B] false is printed to standard out [C] An exception is raised [D] Nothing happens Ans: A Q 55:Consider the following classes: public class Test { public static void test() { [Link](); } public static void print() { [Link]("Test"); } public static void main(String args []) { test(); } } What is the result of compiling and running this class? [A] An exception is raised stating that the method test cannot be found. [B] A runtime exception is raised stating that an object has not been created. [C] The string Test is printed to the standard out. [D] The class fails to compile stating that the variable this is undefined. Ans: D Q 56:Given the following sequence of Java statements 1. 2. 3. 4. 5. 6. 7. StringBuffer sb = new StringBuffer("abc"); String s = new String("abc"); [Link]("def"); [Link]("def"); [Link](1, "zzz"); [Link](sb); [Link]();
Which of the following statements are true:
[A] The compiler [B] The compiler [C] The compiler [D] The compiler Ans: C,D
would would would would
generate generate generate generate
an an an an
error error error error
for for for for
line line line line
1. 2. 4. 6.
Q 57:What is the result of executing the following Java class: import [Link].*; public class FrameTest extends Frame { public FrameTest() { add (new Button("First")); add (new Button("Second")); add (new Button("Third")); pack(); setVisible(true); } public static void main(String args []) { new FrameTest(); } } Select from the following options: [A] Nothing happens. [B] Only the "third" button is displayed. [C] A runtime exception is generated (no layout manager specified). [D] Three buttons are displayed across a window. Ans: B Q 58:Consider the following tags and attributes of tags: 1. CODEBASE 2. ALT 3. NAME 4. CLASS 5. JAVAC 6. HORIZONTALSPACE 7. VERTICALSPACE 8. WIDTH 9. PARAM 10. JAR Which of [A] line [B] line [C] line [D] line Ans: A,D the above can be used within the <APPLET> and </APPLET> tags? 1, 2, 3 2, 5, 6, 7 8, 9, 10 8, 9
Q 59:Which of the following are correct methods for initializing the array "dayhigh" with 7 values? [A] int dayhigh = { 24, 23, 24, 25, 25, 23, 21 }; [B] int dayhigh[] = { 24, 23, 24, 25, 25, 23, 21 }; [C] int[] dayhigh = { 24, 23, 24, 25, 25, 23, 21 }; [D] int dayhigh [] = new int[24, 23, 24, 25, 25, 23, 21]; Ans: ,B,C Q 60:Given the variables defined below: int one = 1; int two = 2;
char initial = '2'; boolean flag = true; Which of the following are valid? [A] if( one == two ){} [B] if( flag ){} [C] switch( flag ){} [D] switch( initial ){} Ans: A,B,D Q 61:What is the result of compiling and executing the following Java class: public class ThreadTest extends Thread { public void run() { [Link]("In run"); suspend(); resume(); [Link]("Leaving run"); } public static void main(String args []) { (new ThreadTest()).start(); } } [A] Compilation will fail in the method main. [B] Compilation will fail in the method run. [C] The string "In run" will be printed to standard out. [D] Both strings will be printed to standard out. Ans: C Q 62:If val = 1 in the code below: switch( val ) { case 1: [Link]( "P" ); case 2: case 3: [Link]( "Q" ); break; case 4: [Link]( "R" ); default: [Link]( "S" ); } Which values would be printed? [A] P [B] Q [C] R [D] S Ans: A,B Q 63:Examine the following class definition: public class Test { public static void test() { print(); } public static void print() { [Link]("Test"); } public void print() { [Link]("Another Test"); } } What is the result of compiling this class: [A] A successful compilation. [B] A warning stating that the class has no main method. [C] An error stating that there is a duplicated method. [D] An error stating that the method test() will call one or other of the print( ) methods.
Ans: C Q 64:Assume that val has been defined as an int for the code below: if( val > 4 ) { [Link]( "Test A" ); } else if( val > 9 ) { [Link]( "Test B" ); } else [Link]( "Test C" ); Which values of val will result in "Test C" being printed: [A] val < 0 [B] val between 0 and 4 [C] val = 0 [D] val between 4 and 9 Ans: A,B,C Q 65:For the code: m = 0; while( m++ < 2 ) [Link]( m ); Which of the following are printed to standard output? [A] 1 [B] 0 [C] 3 [D] 2 Ans: A,D Q 66:Carefully examine the following code: public class StaticTest { static { [Link]("Hi there"); } public void print() { [Link]("Hello"); } public static void main(String args []) { StaticTest st1 = new StaticTest(); [Link](); StaticTest st2 = new StaticTest(); [Link](); } } When will the string "Hi there" be printed? [A] Never. [B] Once when the class is first loaded into the Java virtual machine. [C] Each time a new instance is created. [D] Only when the static method is called explicitly. Ans: B Q 67:Consider the code fragment below: outer: for( int i = 1; i <3; i++ ) { inner: for( j = 1; j < 3; j++ ) { if( j==2 ) continue outer; [Link]( "i = " +i ", j = " + j ); } }
Which of the [A] i = 1, j [B] i = 1, j [C] i = 2, j [D] i = 2, j Ans: A,C
following would be printed to standard output? = 1 = 2 = 1 = 2
Q 68:Consider the following program: public class Test { public static void main (String args []) { boolean a = false; if (a = true) [Link]("Hello"); else 	 [Link]("Goodbye"); } } What is the result: [A] Prints out "Hello" [B] Program does not terminate. [C] Program produces no output but terminates correctly. [D] Prints out "Goodbye" Ans: A Q 69:Consider the code below: void myMethod() { try { fragile(); } catch( NullPointerException npex ) { [Link]( "NullPointerException thrown " ); } catch( Exception ex ) { [Link]( "Exception thrown " ); } finally { [Link]( "Done with exceptions " ); } [Link]( "myMethod is done" ); } What is printed to standard output if fragile() throws an IllegalArgumentExcepti on? [A] "NullPointerException thrown" [B] "Exception thrown" [C] "Done with exceptions" [D] "myMethod is done" Ans: B,C,D Q 70:Consider the following code sample: class Tree{} class Pine extends Tree{} class Oak extends Tree{} public class Forest { public static void main( String[] args ) { Tree tree = new Pine();
if( tree instanceof Pine ) [Link]( "Pine" ); if( tree instanceof Tree ) [Link]( "Tree" ); if( tree instanceof Oak ) [Link]( "Oak" ); else [Link]( "Oops" ); } } Select all choices that will be printed: [A] Pine [B] Forest [C] Tree [D] Oops Ans: A,C,D Q 71:Examine the following code, it includes an inner class: public final class Test4 { class Inner { void test() { if ([Link]); { sample(); } } } private boolean flag = true; public void sample() { [Link]("Sample"); } public Test4() { (new Inner()).test(); } public static void main(String args []) { new Test4(); } } What is the result: [A] Prints out "Sample" [B] Program produces no output but terminates correctly. [C] Program does not terminate. [D] The program will not compile Ans: A Q 72:Carefully examine the following class: public class Test5 { public static void main (String args []) { /* This is the start of a comment if (true) { Test5 = new test5(); [Link]("Done the test"); } /* This is another comment */ [Link] ("The end"); } } What is the result: [A] Prints out "Done the test" and nothing else. [B] Program produces no output but terminates correctly. [C] The program generates a runtime exception.
[D] The program prints out "The end" and nothing else. Ans: D Q 73:Consider the classes defined below: import [Link].*; class Super { int methodOne( int a, long b ) throws IOException { // code that performs some calculations } float methodTwo( char a, int b ) { // code that performs other calculations } } public class Sub extends Super { } Which of the following are legal method declarations to add to the class Sub? Assume that each method is the only one being added [A] public static void main( String args[] ){} [B] float methodTwo(){} [C] long methodOne( int c, long d ){} [D] int methodOne( int c, long d ) throws ArithmeticException{} Ans: A,B Q 74:Which of the following statements about Java's garbage collection are true? [A] The finalize method is always called before an object is garbage collected. [B] The garbage collector can be invoked explicitly using a Runtime object. [C] Any class that includes a finalize method should invoke its superclass' fina lize method. [D] Garbage collection behavior is very predictable. Ans: A,B,C Q 75:The following code defines a simple applet: import [Link]; import [Link].*; public class Sample extends Applet { private String text = "Hello World"; public void init() { add(new Label(text)); } public Sample (String string) { text = string; } } It is accessed form the following HTML page: <html> <title>Sample Applet</title> <body> <applet code="[Link]" width=200 height=200></applet> </body> </html> What is the result of compiling and running this applet: [A] Prints "Hello World". [B] Generates a runtime error. [C] Does nothing. [D] Generates a compile time error. Ans: B
Q 76:For what reasons might a thread stop execution? [A] A thread with higher priority began execution. [B] The thread's wait() method was invoked. [C] The thread invoked its yield() method. [D] The thread's sleep() method was invoked. Ans: A,B,C,D Q 77:Identify the valid assignments. [A] float f = 1.2; [B] char c = '/u004E'; [C] float f = \u0038; [D] int c=0xxAA; Ans: B,C Q 78:If arr[] contains only positive integer values, what does this function do? public int guessWhat( int arr[] ) { int x= 0; for( int i = 0; i < [Link]; i++ ) x = x < arr[i] ? arr[i] : x; return x; } [A] Returns the index of the highest element in the array [B] Returns true/false if there are any elements that repeat in the array [C] Returns how many even numbers are in the array [D] Returns the highest element in the array Ans: D Q 79:Consider the code below: public static void main( String args[] ) { int a = 5; [Link]( cube( a ) ); } int cube( int theNum ) { return theNum * theNum * theNum; } What will happen when you attempt to compile and run this code? [A] It will not compile because cube is already defined in the [Link] cl ass. [B] It will not compile because cube is not static. [C] It will compile, but throw an arithmetic exception. [D] It will run perfectly and print "125" to standard output. Ans: B Q 80:What method(s) from the [Link] class might method() be if the state ment method( -4.4 ) == -4; is true. [A] min() [B] round() [C] trunc() [D] ceil() Ans: B,D Q 81:For the following code: class Super { int index = 5; public void printVal()
{ [Link]( "Super" ); } } class Sub extends Super { int index = 2; public void printVal() { [Link]( "Sub" ); } } public class Runner { public static void main( String argv[] ) { Super sup = new Sub(); [Link]( [Link] + "," ); [Link](); } } What will be printed to standard output? [A] The code will not compile. [B] The code compiles and "5, Super" is printed to standard output. [C] The code compiles and "5, Sub" is printed to standard output. [D] The code compiles and "2, Super" is printed to standard output. Ans: C Q 82:How many objects are eligible for garbage collection once execution has reached the line labeled Line A? String name; String newName = "Nick"; newName = "Jason"; name = "Frieda"; String newestName = name; name = null; //Line A [A] 0 [B] 1 [C] 2 [D] 3 Ans: B Q 83:Which methods does [Link] include for trigonometric computations? [A] sin() [B] cos() [C] tan() [D] toDegree() Ans: A,B,C Q 84:Which method below can change a String object, s ? [A] equals( s ) [B] substring( s ) [C] concat( s ) [D] none of the above will change s Ans: D Q 85:This piece of code: TextArea ta = new TextArea( 10, 3 ); Produces (select all correct statements): [A] a TextArea with 10 rows and up to 3 columns [B] a TextArea with a variable number of columns not less than 10 and 3 rows
[C] a TextArea that may not contain more than 30 characters [D] a TextArea that can be edited Ans: A,D Q 86:public class Test { public void foo() { assert false; /* Line 5 */ assert false; /* Line 6 */ } public void bar() { while(true) { assert false; /* Line 12 */ } assert false; /* Line 14 */ } } What causes compilation to fail? [A] Line 5 [B] Line 6 [C] Line 12 [D] Line 14 Ans: D Q 87:In the list below, which subclass(es) of Component cannot be directly insta ntiated: [A] Panel [B] Dialog [C] Container [D] Frame Ans: C Q 88:Which of the following methods from the [Link] class would be used to draw the outline of a rectangle with a single method call? [A] fillRect() [B] drawRect() [C] fillPolygon() [D] drawPolygon() Ans: B,D Q 89:The Container methods add( Component comp ) and add( String name, Component comp ) will throw an IllegalArgumentException if comp is a: [A] button [B] list [C] window [D] container that contains this container Ans: C,D Q 90:Of the following AWT classes, which one(s) are responsible for implementing the components layout? [A] LayoutManager [B] GridBagLayout [C] FlowLayout [D] ActionListener
Ans: B,C Q 91:Which of the following statements about event handling in JDK 1.1 and later are true? [A] A class can implement multiple listener interfaces [B] If a class implements a listener interface, it only has to overload the meth ods it uses. [C] All of the MouseMotionAdapter class methods have a void return type. [D] None of these Ans: A,C Q 92:What will be the output of the program? public class Test { public static int y; public static void foo(int x) { [Link]("foo "); y = x; } public static int bar(int z) { [Link]("bar "); return y = z; } public static void main(String [] args ) { int t = 0; assert t > 0 : bar(7); assert t > 1 : foo(8); /* Line 18 */ [Link]("done "); } } [A] bar [B] bar done [C] foo done [D] Compilation fails Ans: D Q 93:What will be the output of the program? class PassA { public static void main(String [] args) { PassA p = new PassA(); [Link](); } void start() { long [] a1 = {3,4,5}; long [] a2 = fix(a1); [Link](a1[0] + a1[1] + a1[2] + " "); [Link](a2[0] + a2[1] + a2[2]); } long [] fix(long [] a3) { a3[1] = 7;
return a3; } } [A] 12 15 [B] 15 15 [C] 3 4 5 3 7 5 [D] 3 7 5 3 7 5 Ans: B Q 94:What will be the output of the program? String s = "hello"; Object o = s; if( [Link](s) ) { [Link]("A"); } else { [Link]("B"); } if( [Link](o) ) { [Link]("C"); } else { [Link]("D"); } [A] A [B] B [C] C [D] D Ans: A,C Q 95:Which two of the following are legal declarations for nonnested classes and interfaces? [A] final abstract class Test {} [B] public static interface Test {} [C] final public class Test {} [D] abstract public class Test {} Ans: ,C,D Q 96:What will be the output of the program? int I = 0; outer: while (true) { I++; inner: for (int j = 0; j < 10; j++) { I += j; if (j == 3) continue inner; break outer; } continue outer; } [Link](I); [A] 1
[B] 2 [C] 3 [D] 4 Ans: A Q 97:interface Base { boolean m1 (); byte m2(short s); } which two code fragments will compile? [A] interface Base2 implements Base {} [B] abstract class Class2 implements Base {} [C] abstract class Class2 extends Base {public boolean m1(){ return true; }} [D] abstract class Class2 implements Base {public boolean m1(){ return (7 > 4);} } Ans: B,D Q 98:What will be the output of the program? class Test { public static void main(String [] args) { Test p = new Test(); [Link](); } void start() { boolean b1 = false; boolean b2 = fix(b1); [Link](b1 + " " + b2); } boolean fix(boolean b1) { b1 = true; return b1; } } [A] true true [B] false true [C] true false [D] false false Ans: B Q 99:Choose all valid forms of the argument list for the FileOutputStream constructor shown below: [A] FileOutputStream( FileDescriptor fd ) [B] FileOutputStream( boolean a ) [C] FileOutputStream( String n, boolean a ) [D] FileOutputStream( File f ) Ans: A,C,D Q 100:What will be the output of the program? class PassS { public static void main(String [] args) { PassS p = new PassS();
[Link](); } void start() { String s1 = "slip"; String s2 = fix(s1); [Link](s1 + " " + s2); } String fix(String s1) { s1 = s1 + "stream"; [Link](s1 + " "); return "stream"; } } [A] slip stream [B] slipstream stream [C] stream slip stream [D] slipstream slip stream Ans: D