Which of the following statements is false? A constructor is required to be writ
ID: 3731369 • Letter: W
Question
Which of the following statements is false?
A constructor is required to be written for every class.
The name of the constructor must be the same as the name of the class.
A constructor can be used to initialize instance variables.
A class can have multiple constructors with different parameter lists.
(TCOs 1, 3, and 6) The _____ class can be used to get user input using dialog boxes.
JFrame
Scanner
JPanel
JOptionPane
(TCOs 1, 3, and 6) A(n) _____ has a border and contains all of the normal window controls for your operating system, such as minimize, maximize, and close buttons.
JTable
JButton
JPanel
JFrame
(TCOs 1, 3, and 6) Suppose a JFrame uses GridLayout(2,0). If you add six buttons to the frame, how many columns are displayed?
1
2
3
4
(TCOs 1, 3, and 6) The extends keyword in a class declaration indicates the use of
interfaces.
polymorphism.
composition.
inheritance.
(TCOs 1, 3, and 6) The implements keyword in a class declaration indicates the use of
interfaces.
polymorphism.
composition.
inheritance.
(TCOs 1, 3, and 6) The oldest GUI library for Java is
Swing.
JavaFX.
AWT.
SWT.
(TCOs 1, 3, and 6) Which method must be used to register the event handler called eHandler to a JButton component called btnNew?
btnNew.setHandler(eHandler);
btnNew.addActionListener(eHandler);
eHandler.addActionListener(btnNew);
btnNew.eHandler();
(TCOs 1, 3, and 6) Which of the following statements is false?
You can create a text field with specific text to be displayed.
You can disable editing on a text field.
You can specify the number of columns in a text field.
You can specify the number of rows in a text field.
(TCOs 1, 3, and 6) The handler (e.g., actionPerformed) is a required method in
both source and listener objects.
a listener object.
a source object.
the Object class.
No new data to save. L
Explanation / Answer
Q1. Which of the following statements is false?
Ans: A constructor is required to be written for every class.
Explaination: This is optional, since a constructor is used to initialized objects.
Since this can be done in method or another approach. Thus it's not mandatory
to write or define constructor each time for every class.
Q2. The _____ class can be used to get user input using dialog boxes.
Ans: JOptionPane.
Explaination: Since it takes user input which can be stored in a variable ,like
String name = JOptionPane.showInputDialog(frame, "What's your name?");
Q3.A(n) _____ has a border and contains all of the normal window controls for your operating system, such as minimize,
maximize, and close buttons.
Ans: JFrame.
Explaination: Since JFrame works like the main window where components like labels, buttons, textfields etc. can
be added.
Q4. Suppose a JFrame uses GridLayout(2,0). If you add six buttons to the frame, how many
columns are displayed?
Ans: 3
Explaination: Since basic Constructor for GridLayout is:
GridLayout(int rows, int cols),
Here GridLayout(2,0) represents 2 rows where all controls will be in 2 rows.
For six button , in 2 row 3 columns will be there
Q5. The extends keyword in a class declaration indicates the use of
Ans: inheritance.
Explaination: Since a class can be inherited for another class by extends keyword.
Why not others?
Polymorphism: no use of extends keyword
interface: implements is used
composition: is different logical terms
Q6. The implements keyword in a class declaration indicates the use of
Ans : interface
Explaination: since interface methods are declared only it's methods are defined in another class
using below syntax
class K implements interfaceName {}
Q7. The oldest GUI library for Java is
Ans: awt.
Explaination: This was Java's first attempt at a GUI interface.
Q8. Which method must be used to register the event handler called eHandler to a JButton component
called btnNew?
Ans: btnNew.addActionListener(eHandler);
Explaination: To implement the interface
Q9. Which of the following statements is false?
Ans: You can specify the number of rows in a text field.
Explaination: Since JTextField can take input for one row only by default.
Q10. The handler (e.g., actionPerformed) is a required method in
both source and listener objects.
Ans: a listener objects
Explaination: see below,
public void actionPerformed(ActionEvent e) {
//code for actionlistener
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.