A+ Answers
1. (TCOs 1–8) Which of the following statements is false? (Points : 3)
A private method cannot be accessed by a class in a different package.
A public class can be accessed by a class from a different package.
A protected method can be accessed by a subclass in a different package.
A method with no visibility modifier can be accessed by a class in a different package.
Question 2.2. (TCOs 1–8) What is the output of running class C?
class A {
public A() {
System.out.println(
“The default constructor of A is invoked”);
}
}
class B extends A {
public B() {
System.out.println(
“The default constructor of B is invoked”);
}
}
public class C {
public static void main(String[ ] args) {
B b = new B();
}
}
Nothing displayed
“The default constructor of A is invoked”
“The default constructor of B is invoked” “The default constructor of A is invoked”
“The default constructor of A is invoked” “The default constructor of B is invoked”
“The default constructor of B is invoked”
Question 3.3. (TCOs 1–8) What modifier should you use on the members of a class so that they are not accessible to another class in a different package but are accessible to any subclasses in any package? (Points : 3)
Private
Public
Protected
Use the default modifier
Question 4.4. (TCOs 1–8) Invoking _____ removes all elements in an ArrayList x. (Points : 3)
x.delete()
x.clear()
x.clean()
x.empty()
x.remove()
Question 5.5. (TCOs 1–8) A class design requires that a particular member variable must be accessible by any subclasses of this class, but otherwise not by classes which are not members of the same package. What should be done to achieve this? (Points : 3)
The variable should be marked public.
The variable should be marked private and an accessor method provided.
The variable should be marked private.
The variable should have no special access modifier.
The variable should be marked protected.
Question 6.6. (TCOs 1–8) Which of the following statements is for terminating the program when closing the frame? (Points : 3)
frame.setDefaultCloseOperation(null)
frame.setDefaultCloseOperation(JFrame.STOP_ON_CLOSE)
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
frame.setDefaultCloseOperation(JFrame.TERMINATE_ON_CLOSE)
Question 7.7. (TCOs 1–8) The default layout out of a contentPane in a JFrame is _____ (Points : 3)
GridLayout.
None
FlowLayout.
BorderLayout.
Question 8.8. (TCOs 1–8) The default layout out of a JPanel is _____ (Points : 3)
BorderLayout.
FlowLayout.
GridLayout.
None
Question 9.9. (TCOs 1–8) What is best to describe the relationship between a container and a layout manager? (Points : 3)
Composition
Inheritance
Aggregation
Association
Question 10.10. (TCOs 1–8) Swing components that don’t rely on native GUI are referred to as _____ (Points : 3)
heavyweight components.
GUI components.
non-GUI components.
lightweight components.