aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes IBM's  exam questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "IBM Watch "IBM New topic
Author

IBM's exam questions

Sanjeet Karamchandani
Ranch Hand

Joined: Jul 29, 2000
Posts: 30
Hi,
Here r few questions that r confusing me, plz help.
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 (assuming that classes A B C r within same package)
14) 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 : a c d ( is "option a" wrong? )
17) 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 : b d e
18) 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 : a c e
21) Methods for a Component are:
a) add()
b) setbounds()
c) setVisible()
d) setEnabled()
e) addComponent()
My answer : b 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
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 : d e

Thanks
Sanjeet
deekasha gunwant
Ranch Hand

Joined: May 06, 2000
Posts: 396
Hi sanjeet ,
Here r reply for few few of ur questions help.see if they help u.
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.

your answers were : a c d but
----------------------------------------------------------------
--->>>> C IS NOT CORRECT BECAUSE UNCAUGHT EXCEPTION SHOULD BE LISTED IN THE THROWS CLAUSE OF METHODS NOT IN CLASS DECLARATION .so correct answers are only a,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

Your answers were : a b c but
------------------------------------------------------------
in method m() of class B u can't access the variable d directly. i mean to access var d in method m u need to have an instance of class A. so the correct answers are a,b only
--------------------------------------------------------------
17) 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

your answers were : b d e
------------------------------------------------------
but u can group dameon threads together so answer d is wrong
------------------------------------------------------

18) 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

your answer was : a c e
-----------------------------------------------------------
but since we do have a wrapper class for void. so option e becomes wrong.
-----------------------------------------------------------
21) Methods for a Component are:
a) add()
b) setbounds()
c) setVisible()
d) setEnabled()
e) addComponent()

your answer was : b d
--------------------------------------------------
component class has all the first 4 methods so
options a,b,c,d are corect. there is no method called addComponent() in component class
--------------------------------------------------
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.

your answer was : c
--------------------------------------------------
which is correct .
-------------------------------------------------
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

your answer was : d e
------------------------------------------------
which is correct
-----------------------------------------------

regards
deekasha
Lancy Mendonca
Ranch Hand

Joined: Aug 08, 2000
Posts: 54
With reference to Q14, could someone be kind enough to explain the meaning of the following terms:
Nested top level inner class
member inner class
local class
local inner class


Sun Certified Java Programmer<BR>Oracle Certified DBA
Sanjeet Karamchandani
Ranch Hand

Joined: Jul 29, 2000
Posts: 30
Hi Deekasha,
Thanks for answering my questions but there r few problems
17) 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
but what abt option a, is it true or false

18) 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
your answer was : a c e
-----------------------------------------------------------
but since we do have a wrapper class for void. so option e becomes wrong.
-----------------------------------------------------------
Excuse me but there is a void wrapper class
Thanks
Sanjeet

Hema
Greenhorn

Joined: Aug 01, 2000
Posts: 12
Hi Sanjeet,
18) 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
your answer was : a c e
-----------------------------------------------
You answer is correct. There is a Void wrapper class.
--------------------------------------------------------
21) Methods for a Component are:
a) add()
b) setbounds()
c) setVisible()
d) setEnabled()
e) addComponent()
your answer was : b d
--------------------------------------------------
The answer is b,c,d. Please refer Exam cram , it lists the methods of Component& Container. b,c, d are component methods.
a is container method & there is no method called addcomponent().
however there are container methods getComponentCount() & getComponentAt(int x, int y).
---------------------------------------------------------------
I hv a doubt with yr other question.

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
your answer was d ,e.
---------------------------------------------------------------
I tried compiling & running this code.
import java.awt.*;
import java.applet.Applet;
public class Layoutapplet extends Applet {
public void init(){
setLayout(new BorderLayout());
setFont(new Font("Serif", Font.PLAIN, 14));
add(BorderLayout.NORTH, new Button("North"));
add(BorderLayout.SOUTH, new Button("South"));
add("East", new Button("East"));
add("West", new Button("West"));
add(new Button("Center"));
}
}
And I got the 4 buttons . But there is no center button which says "Center". Can you explain..?
----------------------------------------------------------------
Thanks,
Hema

Sanjeet Karamchandani
Ranch Hand

Joined: Jul 29, 2000
Posts: 30
Hi,
Thanks Hema for answering, but u got something wrong.
21) Methods for a Component are:
a) add()
b) setbounds()
c) setVisible()
d) setEnabled()
e) addComponent()
Well method of component include a,b,c,d. Yes add() method is in component that takes a argument of PopupMenu. Plz look in component class again.

import java.awt.*;
import java.applet.*;
public class LayoutApplet extends Applet {
public LayoutApplet ( ) {
setLayout(new BorderLayout());
setFont(new Font("Serif", Font.PLAIN, 14));
add(BorderLayout.NORTH, new Button("North"));
add(BorderLayout.SOUTH, new Button("South"));
add("East", new Button("East"));
add("West", new Button("West"));
add(new Button("Center"));
}
public void init() {
new LayoutApplet();
}
}
This code is working fine and displays five buttons as expected.
Thanks
Sanjeet
Anonymous
Ranch Hand

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

==================
I think answer d is the correct answer. My explanation follows:
Button is added to panel (p1) which has a FlowLayout, so the button "where is my location?" is at its preferred size.
panel p1 is added to a frame with a BorderLayout, so p1 takes up
the entire frame because nothing else is added but the SIZE OF THE BUTTON will NOT change because the layout for p1 is still
FlowLayout.
Thanks!
yanish
Greenhorn

Joined: Aug 18, 2000
Posts: 21
I'm sorry, but why does everybody say that setbounds() is a method of the Component? or it's just a typo.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Originally posted by chengx:
Regarding Q22
Button is added to panel (p1) which has a FlowLayout, so the button "where is my location?" is at its preferred size.
panel p1 is added to a frame with a BorderLayout, so p1 takes up
the entire frame because nothing else is added but the SIZE OF THE BUTTON will NOT change because the layout for p1 is still
FlowLayout.

You are correct except, BorderLayout defaults to BorderLayout.CENTER if no location is specified in add() which would mean the panel would be displayed in the center (vert and horiz) of the screen.
Sanjeet Karamchandani
Ranch Hand

Joined: Jul 29, 2000
Posts: 30
Hi snyd1437 & chengx,
R u both trying to say that option d is correct. Well, i have tried it and option c seems right and logical coz by in flowlayout the defalut allignment is Centre and not left.
Try it.
Thanks
Sanjeet
Originally posted by snyd1437:
You are correct except, BorderLayout defaults to BorderLayout.CENTER if no location is specified in add() which would mean the panel would be displayed in the center (vert and horiz) of the screen.

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Sorry for the confusion. I agree that answer C is correct.
Hema
Greenhorn

Joined: Aug 01, 2000
Posts: 12
Try running this code, you can definetly say C is correct .
-----------------------------------------------------
import java.awt.*;
public class Layoutframe extends Frame {
public Layoutframe(){
super();
setBounds(20,20,300,180);
setVisible(true);
Button b = new Button("What is my location?");
Panel p1 = new Panel();
p1.add(b);
add(p1);
}
public static void main(String[] arg){
Layoutframe lay= new Layoutframe();
lay.show();
}
}
-------------------------------------------------
Cheers,
Hema
Praveen Kumar
Ranch Hand

Joined: Jul 27, 2000
Posts: 31
I am not able to connect to the IBM mock exam test for last
one month. Whenever I login it gives class exception error. Could u please tell me how did u logged in, the browser u are using and the exact URL.

------------------
Praveen Kumar
Mumbai ,India
email: bades@vsnl.com


Praveen Kumar<BR>Mumbai ,India<BR>email: bades@vsnl.com
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi, guys,
Thanks for correcting me. I forgot the fact that there is only one button added to the panel and the default for FlowLayout is Center not left as pointed out. I know NOW that c is correct and
d is not! Thanks again!
chengx
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
deekasha,
I have a question about the comment you made on Question 10. Please correct me if I am wrong. You said:
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

Your answers were : a b c but
------------------------------------------------------------
in method m() of class B u can't access the variable d directly. i mean to access var d in method m u need to have an instance of class A. so the correct answers are a,b only
--------------------------------------------------------------
It seems to me that for C.t, you need to have an instance of class A too. See the example below:
Class B {
public void m() {
//System.out.println (d); //Compile Error
System.out.println (new A().d);
}
}
Class C extends A {
protected static void s() {};
void t() {
//System.out.println (d); //Compile Error
System.out.println (new A().d);
}
}
So if you consider accessing the variable through an instance is not direct, the only right choice should be: a
Thanx.
Praveen Kumar
Ranch Hand

Joined: Jul 27, 2000
Posts: 31
I am unable to run IBM exam from my m/c for last one month. Whenever I login it gives erro (Fatal Error - a session could not be found or created) Can u provide the exact
URL plus browser name/version/extra settting u all are using.

------------------
Praveen Kumar
Mumbai ,India
email: bades@vsnl.com
 
jQuery in Action, 2nd edition
 
subject: IBM's exam questions