Forums Register Login

IBM Mock test

+Pie Number of slices to send: Send

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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
The answer to one is b and d in my opinion. And the aswer to number two is a in my opinion.
+Pie Number of slices to send: Send
I too think the answer to one is b and d. The answer to two is a.
It's exactly the same and completely different as this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 836 times.
Similar Threads
IBM Mock question
About GridLayout
layout
Frames
Mystery GridBagLayout
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 10:12:57.