Beruflich Dokumente
Kultur Dokumente
MCQ
1. What layout manager should you use so that every component occupies the same size in the container?
A. a FlowLayout
B. a GridLayout
C. a BorderLayout
D. any layout
2. What layout allows to add button defined by button text, and NOT affected by the Frame size?
A. a FlowLayout
B. a GridLayout
C. a BorderLayout
D. any layout
A. jp.setlayout(new FlowLayout());
B. jp.setLayout( new FlowLayout());
C. jp.setLayout(new Flowlayout());
D. jp.setLayout(FlowLayout());
4. What should you import to create a window which extends JFrame class
A. java. awt.*;
B javax.awt.JFrame;
C. javax.swing.*;
D. java.util.*;
A. FlowLayout
B. GridLayout
C. BorderLayout
D. None
A. pl.setBackGround(Color.yellow)
B. pl.setBackground(Color.YELLOW)
C. pl.setBackgroundColor(Color.yellow)
D. setBackground(Color.YELLOW)
8. To specify a font to be bold and italic, use the font style value
A. Font.PLAIN
B. Font.BOLD
C. Font.ITALIC
D. Font.BOLD + Font.ITALIC
9. To set text on button jbt to blue color you use
A. jbt.setColor(Color.blue);
B. jbt.setFontColor(Color.blue)
C. jbt.setForeground(Color.blue)
D. jbt.color = “blue”;
A. jbt.setText(“Submit”);
B. jbt.changeText(“Submit”);
C. jbt.text = “Submit”;
D. jbt.put(“Submit”);
A. p.add(c)
B. p.getContentPane(c)
C. p.insert(c)
D. p.append(c)
A. KeyEvent
B. MouseEvent
C. MouseMotionEvent
D. ActionEvent
14. Which of the following statements registers a panel p as a listener for a button variable jbt?
A. addActionListener(p);
B. jbt.addActionListener(p);
C. jbt.addActionEventListener(p);
D. jbt.addEventListener(p);
15. Which interface should be implemented to listen for a button action event.
A. MouseListener
B. ActionListener
C. FocusListener
D. WindowListener
16. Which method reads the contents of the text field jtf.
A. jtf.getText(s)
B. jtf.getText()
C. jtf.getString()
D. jtf.findString()
17. Which method will display a string s into the text area jta.
A. jta.setText(s)
B. jta.appendText(s)
C. jta.append(s)
D. jta.insertText(s)
18. Which method returns the selected item on a JComboBox jcbo.
A. jcbo.getSelectedIndex()
B. jcbo.getSelectedItem()
C. jcbo.getSelectedIndices()
D. jcbo.getSelectedItems()
A. CheckBoxEvent
B. ItemEvent
C. ComponentEvent
D. ContainerEvent
20. The method __________ gets the text (or caption) of the button jbt.
A. jbt.text()
B. jbt.getText()
C. jbt.findText()
D. jbt.retrieveText().
21. To create a button with an image stored in a file pic.jpg you use
23. Your application implements ActionListener interface. Which statement registers a button bt
with ActionListener?
bt.addActionListener(this);
bt.add(this);
bt.addActionEvent (this);
bt.addEventListener(this);
25. Class Aclass is subclass of Bclass. Class Aclass must start with
class Aclass implements Bclass{}
class Aclass extend Bclass{}
class Bclass extends Aclass{}
class Aclass extends Bclass{}
28. Class contains a method public double getMoney(int rate, double amount);
Which one is overloaded method
public double getMoney (int amount, double rate);
public double getMoney(int percentage, double amount);
public double getMoney (double rate, double amount);
none of above
30. The layout which allows to add not more than 5 components is
E. GridLayout (1, 5)
F. BorderLayout()
G. BorderLayout(5)
H. A and C
1. A user compiles and runs the Java application below that displays what an animal eats depending on its kind:
cat or dog. Write down all lines (input and output) that will be displayed in the console window (10 marks)
import java.util.*;
if ( type.equals("cat"))
an = new Cat( name );
else
an = new Dog( name);
an.eat();
System.out.println("Enter 1 to continue or 0 to exit");
anw = scan.nextInt();
}
}
}
2. The following two classes contain 10 syntax errors, please find and correct them.
/**Selection sort in descending order*/
public class SelectionSort {
/** The method for sorting the numbers */
static selectionSort(int[] list {
for (int i = list.length - 1; i >= 1; i--) {
// Find the maximum in the list[0..i]
int currentMin = list[0]
int currentMinIndex = 0;
1. Write a code for a class WaterTank with attributes fullness and capacity both in litres as double.
Write two constructors (default one and constructor with two parameters)
Write set/get methods for both attributes.
Write custom methods fillTank and drainTank with amount of water in litres as a parameter.
Return type for fillTank is boolean and it returns false if (amount +fullness) is greater than capacity,
otherwise it adds amount to fullness and returns true.
Return type for drainTank is also boolean and returns false if (fullness-amount) is less than zero,
otherwise it reduces fullness by amount and returns true.
2. Write a program which will display a window with a two text fields to enter first name and last name,
two labels (as prompt for text fields), and a button “Register”. Your class must extend JFrame. Add
action listener to the button. When the button is clicked the text entered in text fields is displayed on a
third label, for example “Welcome John Ward!!!”.