My answer : a c d 4) Which of the following are legal?
a) String s = "Russ"; int y = 1; s=s+y;
b) String s = "Russ"; int y = 1; y += s;
c) String s = "Russ"; int y = 1; s+y;
d) String s = "Russ"; int y = 1; y=y+s;
My answer :a 5) After execution of the code below, what are the values of x, y and z?
int x = 5, y = 10, z = 15;x += y++ + ++z;
a) x = 31, y = 11, z = 16
b) x = 30, y = 10, z = 16
c) x = 5, y = 11, z = 16
d) x = 21, y = 10, z = 16 My answer :a 6) int x1 = -1, x2 = -1; x1 = x1 >>> 31; x2 >>= 31;
a) x1 = 1, x2 = -1
b) x1 = -1, x2 = -1
c) x1 = 1, x2 = 0
d) x1 = 1, x2 = 1
My answer : a 7) Which of the following declarations of a top-level class Frog are legal, assuming Animal is an existing class?
a) protected class Frog extends Animal {
b) private class Frog extends Animal {
c) transient class Frog extends Animal {
d) native class Frog extends Animal
My answer : none 8) Which of the following declares an abstract method doit()?
a) abstract public void doit();
b) public abstract void doit();
c) abstract void doit () {}
d) void doit() {}
My answer : a b 9) In regards to exceptions, which of the following are true?
a) An exception can be thrown by a no argument constructor.
b) An exception can only be thrown by a multi argument constructor.
c) Uncaught exceptions should be listed in the throws clause of a class definition.
d) In all cases except exiting the JVM, the finally clause of a try block is executed.
My answer : a c d 10) In classes A, B, and C, which methods have direct access to A.d?
Class A { protected double d=3.14; public static void f() {}; public void g() {}; } Class B { public void m() {}; } Class C extends A { protected static void s() {}; void t() {}; }
a) A.g
b) C.t
c) B.m
d) C.s
My answer : a b c 11) Select all of the statements that are true of the classes Shape and SubShape.
class Test extends Object { public static void main(String args[ ]) { Shape p = new Shape(); Shape q = new SubShape(); System.out.println("p.y = " + p.y + " q.y = "+ q.y); System.out.println("p.getY() = " + p.getY() + q.getY() = " + q.getY()); } } class Shape { int x = 7, y = 7; int getY() {return y;} } class SubShape extends Shape { int x =5, y =5; int getY() {return y;} }
a) p.y = 7, q.y = 7
b) p.getY() = 7
c) q.getY() = 5
d) q.getY() = 7
e) p.getY() = 5
My answer : a b c 12) Given an object design where the Person class is the superclass of the Employee class, which of the following statements best describes this relationship?
My answer : b c d 22) Based upon the code below, what is true about the Frame constructed:
1. public LayoutFrame() { 2. super(); 3. Button b = new Button("What is my location?"); 4. Panel p1 = new Panel(); 5. p1.add(b); 6. add(p1); 7. }
a) The push button is located in the center of the Frame and will expand to all sides.
b) The code does compile successfully because the superclass constructor is called.
c) The size of the push button is just larger than the label.
d) The push button is located in the upper-left hand corner of the Frame.
My answer : c d 23) Based upon the code below, what is true about the Applet constructed?
1. public LayoutApplet ( ) { 2. setLayout(new BorderLayout()); 3. setFont(new Font("Serif", Font.PLAIN, 14)); 4. add(BorderLayout.NORTH, new Button("North")); 5. add(BorderLayout.SOUTH, new Button("South")); 6. add("East", new Button("East")); 7. add("West", new Button("West")); 8. add(new Button("Center")); 9. }
a) Statement 2 is ignored and the default Layout Manager for an Applet is used.
b) There is a compile error on line 6: you cannot mix the use of Strings and Constants to specify the location of components.
c) There is a compile error on line 8: the location specification via a String or Constant is not provided.
d) Five push buttons are drawn, with the largest push button in the center.
e) The code compiles successfully
My answer : e 24) Assuming the code below is part of a Frame subclass, which are true?
1.public LayoutFrame() { 2. setLayout(new GridLayout(1, 3)); 3. Button b = new Button("What is b location?"); 4. Button a = new Button("What is a location?"); 5. Panel p1 = new Panel(); 6. p1.setLayout(new GridLayout(2, 1)); 7. p1.add(a); 8. p1.add(b); 9. add(p1); 10. }
a) Two push buttons are added. Each is half the size of the entire Frame vertically and the entire width, with a above b.
b) Two push buttons are added. Each is half the width of the Frame and the entire length vertically, with a above b.
c) Two push buttons are added, each just larger than the size of the label and located in the center of the Frame.
d) There is a compile error since the superclass constructor is not called.
e) There is a compile error since there is no receiving object specified for the methods in lines 2 and 9.
My answer : d 25) True or False: If a component uses enableEvent() to handle a certain event mask, it may not use an Adapter as a listener for this event.
a) False
b) True
My answer : a 26) Based upon the code listed below, assume that classes A1 and A2 implement the ActionListener interface:
i think the answer to question8 should be a,b and also answers for questions 26 to 30 are correct.iam not sure about the layout questions though.
ravee
Greenhorn
Joined: Feb 18, 2000
Posts: 19
posted
0
Hey, could you give me the url for the IBM mock test? thanks ravee.
Tony Alicea
Desperado
Sheriff
Joined: Jan 30, 2000
Posts: 3219
posted
0
PLEASE POST ONLY ONE QUESTION PER POST. Thanks
Tony Alicea Senior Java Web Application Developer, SCPJ2, SCWCD
sanjay verma
Greenhorn
Joined: Feb 08, 2001
Posts: 1
posted
0
1 a b d
Huang Hui
Greenhorn
Joined: May 27, 2002
Posts: 1
posted
0
Originally posted by shan: 1 a,b,c 2,3,4 ,5 ,6 ,7 ,11,12 ,13 ,15 ,16 ,19 , 20 --correct 8 b,c 9 a,d 10 a,b 14 c,d 17 b,e 18 a,c 21 a,c,d rest after some time.........
Paulo Silveira
Ranch Hand
Joined: May 21, 2002
Posts: 32
posted
0
24 is A, not D!!! it is assumed that the add() is the same as this.add(), and the class is a subclass of a Frame, as the question says
vasu chowdary
Ranch Hand
Joined: Mar 15, 2008
Posts: 84
posted
0
i am fairly new to java.i think your answer for q.no 4 is wrong.it may be both A&C
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35249
7
posted
0
Vaasu, welcome to JavaRanch. We're pleased to have you with us, but please DontWakeTheZombies. This question was asked 8 years ago; it's fair to assume that nobody is still waiting for an answer. [ March 15, 2008: Message edited by: Ulf Dittmer ]