jQuery in Action, 2nd edition*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes IBM Mock  test Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "IBM Mock  test" Watch "IBM Mock  test" New topic

IBM Mock test

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi All!,
I just took the mock test and I'm not sure which of my answers are wrong. can anybody check it out. thanks in adv.

Which statements are true about Java garbage collection?

a) It is not possible to predict when garbage collection will happen

b) It is not possible to force garbage collection reliably

c) It is not possible to turn garbage collection off

d) The applications programmer must allocate and free memory

My answer : a b d
Consider the following line of code:

int y[ ] = new int[20];

After execution, which statements are true?

a) y[0] is null

b) y[19] is 0

c) y[20] is undefined / does not exist

d) y.length is 20

My answer : b c d
Which of the following signatures are valid for a main() method of an application?

a) public static void main(String args[])

b) public void main(String args[])

c) public static void main(String [] args)

d) public static void main(String arg[])

e) public static int main(String args[])

My answer : a c d
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
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
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
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
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
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
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
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
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
Given an object design where the Person class is the superclass of the Employee class, which of the following statements best describes this relationship?

a) aggregation

b) "has a"

c) "is a"

d) polymorphism

e) independence

My answer : c
What JDK tool is used to execute a compiled class?

a) javah

b) javap

c) javarun

d) java

My answer : d
Which of the following statements is true?

a) An interface can contain a nested top-level inner class.

b) An interface can contain a member inner class.

c) A member inner class can implement an interface.

d) A static method can contain a local class.

e) A static method can contain a nested top-level class.

My answer : c e
The synchronized keyword may be used in which of the following contexts:

a) Class declarations

b) Method declarations

c) Code block declarations

d) field declarations

My answer : b c
Which of the following method pairs are best used for controlling thread communication?

a) stop() and resume()

b) threadWait() and threadNotify()

c) wait() and notify()

d) run() and destroy()

My answer : c
With respect to User and Daemon threads:

a) Daemon threads can not be destroyed

b) Running User threads prevent a JVM from terminating program

c) Running Daemon threads prevent a Java VM from terminating program

d) Daemon threads can not be grouped together

e) The JVM can terminate program when only daemon threads are running

My answer : a b e
Primitive type wrapper classes:

a) Allow primitive types to behave as reference types

b) Allow operator overloading to be implemented for primitive numeric types

c) Provide string parsing and conversion methods

d) Provide arithmetic operators such as plus and minus

e) Are provided for all primitive types, including void

My answer : c e
When comparing Strings and StringBuffers, which of the following statements evaluate correctly and return true:

a) new String("IBMVAJava").toString().equals(new String("IBMVAJava"))

b) new StringBuffer("IBMVAJava").equals(new StringBuffer("IBMVAJava"))

c) new StringBuffer("IBMVAJava") == (new StringBuffer("IBMVAJava"))

d) new String("IBMVAJava") == new String("IBMVAJava")

My answer : a
Which of the following are subclasses of Container?

a) ScrollPane

b) ComboBox

c) Slider

d) Event

My answer : a
Methods for a Component are:

a) add()

b) setbounds()

c) setVisible()

d) setEnabled()

e) addComponent()

My answer : b c d
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
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
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
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
Based upon the code listed below, assume that classes A1 and A2 implement the ActionListener interface:

1. TextField tf = new TextField("This is a test");
2. ActionListener ac1 = new A1();
3. ActionListener ac2 = new A2();
4. tf.addActionListener(ac1);
5. tf.addActionListener(ac2);

a) Lines 2 and 3 generate errors when compiled.

b) This code compiles and runs successfully.

c) Line 5 will cause an exception when the code is run.

d) The enableEvents() method must be registered to the TextField.

e) This code will not run without error.

My answer : b
How would you create a font to be 12 point, bold, sans serif:

a) Font font = new Font("SanSerif", Font.BOLD, 12)

b) Font font = new Font(Font.BOLD, 12, SansSerif)

c) g.setFont("SansSerif", Font.BOLD, 12)

d) g.setFont(SansSerif, BOLD, 12)

My answer : a
FilterInputStream chaining, or concatenation may best be defined as the:

a) Ability to open a high level input stream on a lower level input stream

b) Ability for the constructor of one stream to call that of another

c) Ability to redirect the output of one stream to the input of another

d) Ability to sequentially open a collection of streams

My answer : a
Which of the following Stream constructors are valid? You may assume the import statement:

import java.io.*

for all statements.

a) new ObjectOutputStream(new FileOutputStream("SavedData.obj"));

b) new CharArrayReader(new File("SavedData.obj"));

c) new ObjectInputStream(new File("SavedData.obj"));

d) new OutputStream(new FileOutputStream("SavedData.obj"));

My answer : a
The following are true of Java character-oriented streams:

a) They provide support for character conversion between Unicode and ASCII

b) They all implement the CharacterStream Interface

c) They inherit from either the Reader or Writer abstract classes

d) They are restricted to 2^16 (2 raised to power of 16) in length

My answer : c

josephine chen
Ranch Hand

Joined: Oct 29, 2002
Posts: 216
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.........
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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.

Joined: Feb 18, 2000
Posts: 19
could you give me the url for the IBM mock test?
Tony Alicea

Joined: Jan 30, 2000
Posts: 3222

Tony Alicea
Senior Java Web Application Developer, SCPJ2, SCWCD
sanjay verma

Joined: Feb 08, 2001
Posts: 1
1 a b d
Huang Hui

Joined: May 27, 2002
Posts: 1
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
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: 89
i am fairly new to java.i think your answer for q.no 4 is wrong.it may be both
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 41108
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 ]

Ping & DNS - my free Android networking tools app
I agree. Here's the link: http://aspose.com/file-tools
subject: IBM Mock test
Similar Threads
IBM's exam questions
Garbage Collection
Switch Statement
Garbage collection
mock question about "case"