Question 11)
You want to loop through an array and stop when you come to the last element. Being a good java programmer and forgetting everything you ever knew about C/C++ you know that arrays contain information about their size. Which of the following can you use?
1)myarray.length();
2)myarray.length;
3)myarray.size
4)myarray.size();
Answer to Question 11
--------------------------------------------------------------------------------
Question 12)
What best describes the appearance of an application with the following code?
import java.awt.*;
public class FlowAp extends Frame{
public static void main(String argv[]){
FlowAp fa=new FlowAp();
fa.setSize(400,300);
fa.setVisible(true);
}
FlowAp(){
add(new Button("One"));
add(new Button("Two"));
add(new Button("Three"));
add(new Button("Four"));
}//End of constructor
}//End of Application
1) A Frame with buttons marked One to Four placed on each edge.
2) A Frame with buutons marked One to four running from the top to bottom
3) A Frame with one large button marked Four in the Centre
4) An Error at run time indicating you have not set a LayoutManager
Answer to Question 12
--------------------------------------------------------------------------------
Question 13)
How do you indicate where a component will be positioned using Flowlayout?
1) North, South,East,West
2) Assign a row/column grid reference
3) Pass a X/Y percentage parameter to the add method
4) Do nothing, the FlowLayout will position the component
Answer to Question 13)
--------------------------------------------------------------------------------
Question 14)
How do you change the current layout manager for a container
1) Use the setLayout method
2) Once created you cannot change the current layout manager of a component
3) Use the setLayoutManager method
4) Use the updateLayout method
Answer to Question 14)
--------------------------------------------------------------------------------
Question 15)
Which of the following are fields of the GridBagConstraints class?
1) ipadx
2) fill
3) insets
4) width
Answer to Question 15)
--------------------------------------------------------------------------------
Question 16)
What most closely matches the appearance when this code runs?
import java.awt.*;
public class CompLay extends Frame{
public static void main(String argv[]){
CompLay cl = new CompLay();
}
CompLay(){
Panel p = new Panel();
p.setBackground(Color.pink);
p.add(new Button("One"));
p.add(new Button("Two"));
p.add(new Button("Three"));
add("South",p);
setLayout(new FlowLayout());
setSize(300,300);
setVisible(true);
}
}
1) The buttons will run from left to right along the bottom of the Frame
2) The buttons will run from left to right along the top of the frame
3) The buttons will not be displayed
4) Only button three will show occupying all of the frame
Answer to Question 16)
--------------------------------------------------------------------------------
Question 17)
Which statements are correct about the anchor field?
1) It is a field of the GridBagLayout manager for controlling component placement
2) It is a field of the GridBagConstraints class for controlling component placement
3) A valid setting for the anchor field is GridBagConstraints.NORTH
4) The anchor field controls the height of components added to a container
Answer to Question 17)
--------------------------------------------------------------------------------
Question 18)
What will happen when you attempt to compile and run the following code?
public class Bground extends Thread{
public static void main(String argv[]){
Bground b = new Bground();
b.run();
}
public void start(){
for (int i = 0; i <10; i++){
System.out.println("Value of i = " + i);
}
}
}
1) A compile time error indicating that no run method is defined for the Thread class
2) A run time error indicating that no run method is defined for the Thread class
3) Clean compile and at run time the values 0 to 9 are printed out
4) Clean compile but no output at runtime
Answer to Question 18)
--------------------------------------------------------------------------------
Question 19)
10)When using the GridBagLayout manager, each new component requires a new instance of the GridBagConstraints class. Is this statement
1) true
2) false
Answer to Question 19)
--------------------------------------------------------------------------------
Question 20)
Which most closely matches a description of a Java Map?
1) A vector of arrays for a 2D geographic representation
2) A class for containing unique array elements
3) A class for containing unique vector elements
4) An interface that ensures that implementing classes cannot contain duplicate keys
Answer to Question 20)