• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

IBM Mock test

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi
Two question from IBM mock

1)
Based upon the code below, what is true about the Frame constructed:

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 push button is located at the top of the Frame and centered.

c) The code does compile successfully because the superclass constructor is called.

d) The size of the push button is just larger than the label.

e) The push button is located in the upper-left hand corner of the Frame.


Multiple Select - Please select all of the correct answers (this question has 2 correct choices).

2)
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) There is a compile error since there is no receiving object specified for the methods in lines 2 and 9.

d) There is a compile error since the superclass constructor is not called.

Single Select - Please select the best answer (one and only one choice must be selected).

According to me Answer is :
Ans 1: code compile successfully and there is no output becoz no setvisible,setsize method in code.
Ans 2: Compile successfully - no output.

Que 1 say there is two correct choice.
Que 1 say there is only one correct choice.

pls clarify.
Best Regards
Avi
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see answer "a" as being the only correct answer to both questions. Two points on question one. The superclass constructer will be called anyway without the specific call so answer "c" is "wrong"(the new test tells you how many answers are correct). Point2 this is important! on the real test in the instructions they tell you to assume that all other code for the class is complete and correct. So in the case of question one you should assume that a LayoutFrame object was created and set visible in the main() method. Im not sure what your question was about Question 2.
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Avi
These 2 questions show only the relevant constructors and you can safely assume that the surrounding code will do all necessary basic operations, like setting size and making visible.
The first question does have 2 correct choices. It is asking you about the default layout manager for a Panel and what happens when you add components to one container and then add that container to another container.
The second question does indeed have a single correct answer. You need to understand GridLayout constructors and behaviour to answer this one.
I you get stuck, try running the sample code as part of a program. Here's a sample.

Hope this helps.
 
greg clarke
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Randall Twede:
I see answer "a" as being the only correct answer to both questions. Two points on question one. The superclass constructer will be called anyway without the specific call so answer "c" is "wrong"(the new test tells you how many answers are correct). Point2 this is important! on the real test in the instructions they tell you to assume that all other code for the class is complete and correct. So in the case of question one you should assume that a LayoutFrame object was created and set visible in the main() method. Im not sure what your question was about Question 2.


Randal
"a" is not the correct answer in the first case. There are 2 correct answers and "a" is not one of them. Try the code.
Avi
If you don't yet understand the questions, run the code to see what they produce. You might still have questions at that point, and I suggest you post them then.
 
Ranch Hand
Posts: 625
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The answer to one is b and d in my opinion. And the aswer to number two is a in my opinion.
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I too think the answer to one is b and d. The answer to two is a.
 
reply
    Bookmark Topic Watch Topic
  • New Topic