Beginning Java with NetBeans: Chapter 13 How to work with inner classes, enumera
ID: 3735420 • Letter: B
Question
Beginning Java with NetBeans: Chapter 13
How to work with inner classes, enumerations, and documentation
MULTIPLE CHOICE [Answers are in tables – delete all but the correct answer’s cell]
1. What can you call an inner class that doesn’t have a name?
a. an interface
b. an anonymous class
c. a public class
d. an event class
2. An inner class can be coded
a. within a class
b. within an abstract method of a class
c. within an enumeration
d. all of the above
3. An inner class can’t
a. access variables and methods of its outer class
b. contain instance variables
c. contain regular methods
d. contain static methods
4. What does the following code do?
JButton button1 = new JButton("Test Button"); button1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("Button 1 clicked!"); }
});
a. use an enumeration to implement the ActionListener interface
b. use an anonymous classs to implement the ActionListener interface
c. use an enumeration to implment the ActionEvent interface
d. use an anonymous class to implment the ActionEvent interface
5. Each constant within an enumeration is assigned
a. an integer value beginning with zero
b. an integer value beginning with one
c. the integer value you specify
d. the String object you specify
6. Which of the following can you not do with an enumeration?
a. Declare a variable as an enumeration type
b. Use an enumeration as a parameter type
c. Use an integer in place of a constant defined by an enumeration
d. Store an enumeration in its own file
7. An enumeration inherits methods from which of the following classes?
a. java.lang.Object
b. java.lang.Enum
c. both a and b
d. neither a nor b
8. Which of the following is a benefit of using javadoc comments?
a. They make your classes easier to debug.
b. They allow other programmers to view the source code for your class.
c. They make it easy for other programmers to learn about your class.
d. They show other programmers how to code a class.
9. Which of the following is a valid javadoc comment?
a. // Calculates the balance due //
b. /* Calculates the balance due */
c. /* Calculates the balance due **/
d. /** Calculates the balance due */
10. Which of the following is not true about generated Java documentation?
a. It indicates the package that a class belongs to.
b. It lists all public methods of the class.
c. It includes the code that implements each documented method.
d. It lets you view classes by package.
11. Where must you code the javadoc comment for a method?
a. Before the class declaration
b. Before the method declaration
c. After the method declaration but before the first statement in the method
d. After the closing brace for the method
12. In what type of file is javadoc documentation stored?
a. class file
b. java file
c. html file
d. txt file
COMPLETION
13. Enumerations are ________________, which means that you can’t pass an int value to a method parameter that specifies an enumeration.
14. You can use ________________ within a javadoc comment to apply formatting to the text when it’s displayed.
15. To include documentation for parameters and return types in javadoc documentation, you use ________________ tags.
16. To view javadoc documentation, you use a ________________.
Explanation / Answer
1. What can you call an inner class that doesn’t have a name?
a. an interface
b. an anonymous class
c. a public class
d. an event class
Answer:-
--------
b. an anonymous class
Explanation:- an anonymous class is an inner class without a name and for which only a single object is created. An anonymous inner class can be useful when making an instance of an object with overloading methods of a class or interface.
2. An inner class can be coded
a. within a class
b. within an abstract method of a class
c. within an enumeration
d. all of the above
Answer:-
---------
d. all of the above
3. An inner class can’t
a. access variables and methods of its outer class
b. contain instance variables
c. contain regular methods
d. contain static methods
Answer:-
---------
d. contain static methods
Explanation:- An inner class instance can be created only from an outer class instance. that's why it doesn't contain Static methods.
4. What does the following code do?
JButton button1 = new JButton("Test Button");
button1.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
System.out.println("Button 1 clicked!");
}
});
a. use an enumeration to implement the ActionListener interface
b. use an anonymous classs to implement the ActionListener interface
c. use an enumeration to implment the ActionEvent interface
d. use an anonymous class to implment the ActionEvent interface
Answer:-
c. use an enumeration to implment the ActionEvent interface
5. Each constant within an enumeration is assigned
a. an integer value beginning with zero
b. an integer value beginning with one
c. the integer value you specify
d. the String object you specify
Answer:-
a. an integer value beginning with zero
6. Which of the following can you not do with an enumeration?
a. Declare a variable as an enumeration type
b. Use an enumeration as a parameter type
c. Use an integer in place of a constant defined by an enumeration
d. Store an enumeration in its own file
Answer:-
c. Use an integer in place of a constant defined by an enumeration
7. An enumeration inherits methods from which of the following classes?
a. java.lang.Object
b. java.lang.Enum
c. both a and b
d. neither a nor b
Answer:-
c. both a and b
Explanation:-
The java.lang.Enum class is the common base class of all Java language enumeration types
which supports various types of methods.This class inherits methods from the java.lang.Object.
8. Which of the following is a benefit of using javadoc comments?
a. They make your classes easier to debug.
b. They allow other programmers to view the source code for your class.
c. They make it easy for other programmers to learn about your class.
d. They show other programmers how to code a class.
Answer:-
c. They make it easy for other programmers to learn about your class.
9. Which of the following is a valid javadoc comment?
a. // Calculates the balance due //
b. /* Calculates the balance due */
c. /* Calculates the balance due **/
d. /** Calculates the balance due */
Answer:-
d. /** Calculates the balance due */
10. Which of the following is not true about generated Java documentation?
a. It indicates the package that a class belongs to.
b. It lists all public methods of the class.
c. It includes the code that implements each documented method.
d. It lets you view classes by package.
Answer:-
b. It lists all public methods of the class.
11. Where must you code the javadoc comment for a method?
a. Before the class declaration
b. Before the method declaration
c. After the method declaration but before the first statement in the method
d. After the closing brace for the method
Answer:-
c. After the method declaration but before the first statement in the method
12. In what type of file is javadoc documentation stored?
a. class file
b. java file
c. html file
d. txt file
Answer:-
c. html file
COMPLETION
13. Enumerations are generic constants, which means that you can’t pass an int value to a method parameter that specifies an enumeration.
14. You can use JavaDocTool within a javadoc comment to apply formatting to the text when it’s displayed.
15. To include documentation for parameters and return types in javadoc documentation, you use HTML(@return) tags.
16. To view javadoc documentation, you use a JavaDocTool.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.