• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

IBM's exam questions

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sanjeet Karamchandani
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for the confusion. I agree that answer C is correct.
 
Hema
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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: [email protected]
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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: [email protected]
 
Can you shoot lasers out of your eyes? Don't look at this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic