1 .
What is the correct ordering for the import, class and package declarations
when found in a single file? [Link], import, class [Link], import, package C
.import, package, class [Link], class, import 2 . Which methods can not be le
gally applied to a string object? [Link](String) [Link](Object) [Link]() D.r
ound() 3 . What will be the result of compiling the following code: public class
Test { public static void main (String args []) { int age; age = age + 1; Syste
[Link]("The age is " + age); } } [Link] and runs with no output [Link]
piles and runs printing out The age is 1 [Link] but generates a runtime erro
r [Link] not compile 4 . Suppose we try to compile and run the following : publi
c class Test{ public static void main(String arg[]){ int j; for(int i = 10, j =
0; i > j; j++){ i = i -1; } //Statement can go here } } Which of the following s
tatements about this code are correct? [Link] loop initializer uses the correct f
orm to set value of i and j [Link] loop initializer is not legal and code will no
t compile for that reason [Link] we put the following statement after the loop, it
would report "i = 5 j = 5" [Link]("i = " + i + " j = " + j); [Link] w
e put the following statement after the loop, it would report "j = 5" [Link]
.println(" j = " + j); 5 . Which of these is the correct format to use to create
the literal char value a? A.'a' B."a" [Link] Character(a) D.\000a
6 . What happen when we try to compile and run code containing the following lin
es? String s = "12345"; String t = new String(s); if(s == t then) [Link]
ntln(t + "==" + s); else [Link](t + "!=" + s); [Link] compiler object
s to the use of == with reference variables in line 3 [Link] program compiles an
prints "12345=12345" [Link] program compiles an prints "12345!=12345" D.A runtime
exception occurs in line 3 7 . What is the legal range of a byte integral type
127 C.( 32,768) 32,767 D.( 256)
255 8 . What will be the resu
? A.0 - 65, 535 B.( 128)
lt of compiling the following code: public class Test { static int age; public s
tatic void main (String args []) { age = age + 1; [Link]("The age is
" + age); } } [Link] and runs with no output [Link] and runs printing o
ut The age is 1 [Link] but generates a runtime error [Link] not compile 9 .
Which of the following is illegal [Link] i = 32; [Link] f = 45.0; [Link] l = 40;
[Link] d = 45.0; 10 . Which assignments are illegal? [Link] f = -412; [Link]
le d = 0x12345678; [Link] s = 10; [Link] other = (int)true; 11 . Which of the fo
llowing represents an octal number? A.0x12 B.32O C.032
D.(octal)2 12 . Which of the following are acceptable? [Link] o = new Button("
A"); [Link] flag = true; [Link] p = new Frame(); [Link] p = new Applet(); 1
3 . 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 Te
st(); } public Test () { [Link]("In test"); [Link](this)
; int temp = [Link]; if (temp > 5) { [Link](temp); } } } [Link] c
lass will not compile [Link] compiler reports and error at line 2 [Link] compiler
reports an error at line 9 [Link] value 10 is one of the elements printed to the
standard output 14 . Which of the following is correct: [Link] temp [] = new S
tring {"j" "a" "z"}; [Link] temp [] = { "j " " b" "c"} [Link] temp [] = {"a"
, "b", "c"} [Link] temp = {"a", "b", "c"} 15 . What is the correct declaration
of an abstract method that is intended to be public: [Link] abstract void add
(); [Link] abstract void add() {} [Link] abstract add(); [Link] virtual ad
d(); 16 . Given the following code: public class Test { ? } Which of the followi
ng can be used to define a constructor for this class: [Link] void Test() {?}
[Link] Test() {?} [Link] static Test() {?} [Link] static void Test() {?}
17 . Which of the following are not acceptable to the Java compiler: [Link] (2 ==
3) [Link]("Hi"); [Link] (2 = 3) [Link]("Hi"); [Link] (2 != 3
) [Link]("Hi"); [Link] ([Link]("hello")) [Link]("H
i"); 18 . Assuming a method contains code which may raise an Exception (but not
a RuntimeException) what is the correct way for a method to indicate that it doe
s not handle that exception [Link] Exception [Link] Exception [Link] Exception
[Link]'t need to specify anything 19 . What is the result of executing the follo
wing code, using the parameters 4 and 0 : public void divide(int a, int b) { try
{ int c = a / b; } catch (Exception e) { [Link]("Exception "); } fina
lly { [Link]("Finally"); } [Link] out: Exception Finally [Link]
out: Finally [Link] out: Exception [Link] output 20 . Given the following classe
s defined in separate files: class Vehicle { public void drive() { [Link]
intln("Vehicle: drive"); } } class Car extends Vehicle { public void drive() { S
[Link]("Car: drive"); } } public class Test { public static void main
(String args []) { Vehicle v; Car c; v = new Vehicle(); c = new Car(); [Link](
); [Link](); v = c; [Link](); } } What will be the effect of compiling and run
ning this class Test? [Link] a Compiler error on the statement v= c; [Link]
rates runtime error on the statement v= c; [Link] out:
Vehicle: drive Car: drive Car: drive [Link] out: Vehicle: drive Car: drive Veh
icle: drive 21 . Where in a constructor, can you place a call to a constructor d
efined in the super class? [Link] [Link] first statement in the constructor C
.The last statement in the constructor [Link] can't call super in a constructor 2
2 . What class must an inner class extend: [Link] top level class [Link] Object cl
ass [Link] class or interface [Link] must extend an interface 23 . In the following
code which is the earliest statement, where the object originally held in emplo
yee, may be garbage collected: public class Test { public static void main (Stri
ng args []) { Employee e = new Employee("Bob", 48); [Link](); [Link]
.println([Link]()); e = null; e = new Employee("Denise", 36); [Link]
ePay(); [Link]([Link]()); } } [Link] 10 [Link] 11 [Link] 7 D
.Line 8 24 . Which of the following methods are not defined on the Graphics clas
s: [Link](int, int, int, int) [Link](Image, int, int, ImageObserver) C.
drawString(String, int, int) [Link](Object); 25 . Which of the following la
yout managers honours the preferred size of a component: [Link] [Link]
ut [Link]
[Link] 26 . Given the following code what is the effect of a being 5: publ
ic 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);
} } } } [Link] a runtime error [Link] an out of bounds exception [Link] t
he values: 1, 2, 2, 4 [Link] no output 27 . What is the effect of issuing a
wait() method on an object [Link] a notify() method has already been sent to that
object then it has no effect [Link] object issuing the call to wait() will halt u
ntil another object sends a notify() or notifyAll() method [Link] exception will b
e raised [Link] object issuing the call to wait() will be automatically synchroni
zed with any other objects using the receiving object. 28 . The layout of a cont
ainer can be altered using which of the following methods: [Link](aLayoutMa
nager); [Link](aLayoutManager); [Link](aLayoutManager); [Link]
r(aLayoutManager); 29 . Using a FlowLayout manager, which is the correct way to
add elements to a container: [Link](component); [Link]("Center", component); [Link]
(x, y, component); [Link](component); 30 . Given that a Button can generate an Ac
tionEvent which listener would you expect to have to implement, in a class which
would handle this event? [Link] [Link] [Link] D.A
ctionListener 31 . Assuming we have a class which implements the ActionListener
interface, which method should be used to register this with a Button? [Link]
ener(*);
[Link](*); [Link](*); [Link](*); 32 . In order
to cause the paint(Graphics) method to execute, which of the following is the mo
st appropriate method to call: [Link]() [Link]() [Link](Graphics) [Link](
Graphics) 33 . What Graphics methods will draw the outline of a square? [Link]
ct() [Link]() [Link]() [Link]() 34 . The setForeground() and
setBackground() methods are defined in class [Link] [Link] [Link]
[Link] 35 . Which of the following illustrates the correct way to pass a param
eter into an applet: A.<applet code=[Link] age=33 width=100 height=100> B.<p
aram name=age value=33> C.<applet code=[Link] name=age value=33 width=100 he
ight=100> D.<applet Test 33> 36 . Which of the following is incorrect when creat
es InputStreamReader? [Link] InputStreamReader(new FileInputStream("data")); [Link]
w InputStreamReader(new FileInputStream("data"),"UTF8"); [Link] InputStreamReader
(new BufferedReader("data")); [Link] InputStreamReader([Link]); 37 . What is t
he permanent effect on the file system of writing data to a new FileWriter("repo
rt"), given the file report already exists;? [Link] data is appended to the file
[Link] exception is raised as the file already exists [Link] data is written to ran
dom locations within the file [Link] file is replaced with a new file 38 . What i
s the effect of adding the sixth element to a vector created in the following ma
nner: new Vector(5, 10);
[Link] IndexOutOfBounds exception is raised. [Link] vector grows in size to a capac
ity of 10 elements [Link] vector grows in size to a capacity of 15 elements [Link]
hing, the vector will have grown when the fifth element was added 39 . The Vecto
r class provides storage for object references in the order of addition and auto
matically epands as needed. Which of the following classes is closed in function
to the Vector class? [Link] [Link] [Link]
nkedList [Link] 40 . What is the result of executing the following cod
e when the value of x is 2: switch (x) { case 1: [Link](1); case 2:
case 3: [Link](3); case 4: [Link](4); } [Link] is pri
nted out [Link] value 3 is printed out [Link] values 3 and 4 are printed out [Link]
values 1, 3 and 4 are printed out 41 . Consider the following example: class Fi
rst { public First (String s) { [Link](s); } } public class Second e
xtends First { public static void main(String args []) { new Second(); } } What
is the result of compiling and running the Second class? [Link] happens [Link]
instance of the class Second is created [Link] exception is raised at runtime stat
ing that there is no null parameter constructor in class First. [Link] class seco
nd will not compile as there is no null parameter constructor in the class First
42 . What is the result of executing the following fragment of code: boolean fl
ag = false; if (flag = true) { [Link]("true"); } else { [Link].p
rintln("false"); } [Link] is printed to standard out
[Link] is printed to standard out [Link] exception is raised [Link] happens 43
. Consider the following classes: public class Test { public static void test()
{ [Link](); } public static void print() { [Link]("Test"); } pu
blic static void main(String args []) { test(); } } What is the result of compil
ing and running this class? [Link] string Test is printed to the standard out. B.
A runtime exception is raised stating that an object has not been created. [Link]
exception is raised stating that the method test cannot be found. [Link] class fa
ils to compile stating that the variable this is undefined. 44 . Examine the fol
lowing 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 thi
s class: A.A successful compilation. B.A warning stating that the class has no m
ain method. [Link] error stating that there is a duplicated method. [Link] error sta
ting that the method test() will call one or other of the print() methods. 45 .
Given the following sequence of Java statements StringBuffer sb = new StringBuff
er("abc"); String s = new String("abc"); [Link]("def"); [Link]("def"); sb.i
nsert(1, "zzz"); [Link](); Which of the following statements are true: [Link] com
piler would generate an error for line 1. [Link] compiler would generate an error
for line 2. [Link] compiler would generate an error for line 3.
[Link] compiler would generate an error for line 4. 46 . What is the result of ex
ecuting the following Java class: import [Link].*; public class FrameTest exte
nds Frame { public FrameTest() { add (new Button("First")); add (new Button("Sec
ond")); add (new Button("Third")); pack(); setVisible(true); } public static voi
d main(String args []) { new FrameTest(); } } What is the result: A.A runtime ex
ception is generated (no layout manager specified). [Link] the "third" button is
displayed. [Link] the "first" button is displayed. [Link] the "second" button i
s displayed. 47 . Which of the following are legal ways to construct a RandomAcc
essFile: [Link]("data", "r"); [Link]("r", "data"); [Link]
domAccessFile("data", "read"); [Link]("read", "data"); 48 . If you r
un the following code on a on a PC from the directory c:\source: import [Link].
*; class Path { public static void main(String[] args) throws Exception { File f
ile = new File("[Link]"); [Link]([Link]()); } } [Link]
[Link] [Link]\[Link] C.c:\source\[Link] D.c:\source 49 . Carefully examine
the following code: public class StaticTest { static { [Link]("Hi t
here"); } public void print() { [Link]("Hello"); } public static voi
d main(String args []) { StaticTest st1 = new StaticTest(); [Link](); StaticT
est st2 = new StaticTest(); [Link]();
} } When will the string "Hi there" be printed? [Link]. [Link] time a new insta
nce is created. [Link] when the class is first loaded into the Java virtual mach
ine. [Link] when the static method is called explicitly. 50 . Question 3: What i
s the proper way of defining a class named Key so that it cannot be subclassed?
[Link] final class Key { } [Link] class Key { } [Link] Key {final;} [Link]
al class Key { } 51 . What is the name of the interface that can be used to defi
ne a class that can execute within its own thread? [Link] [Link] [Link] D.E
xecutable 52 . What is the name of the method used to schedule a thread for exec
ution? [Link](); [Link](); [Link](); [Link](); 53 . All methods may cause a th
read to stop executing. Except? [Link](); [Link](); [Link](); [Link]();