Sheet 3 - Nested Classes
Sheet 3 - Nested Classes
Nested Classes
Questions
1. The following program Problem.java doesn't compile. What do you need to do to make it compile?
Why?
2. Use the Java API documentation for the Box class (in the javax.swing package)
to help you answer the following questions.
a. What static nested class does Box define?
b. What inner class does Box define?
c. What is the superclass of Box's inner class?
d. Which of Box's nested classes can you use from any class?
e. How do you create an instance of Box's Filler class?
3. Get the following file Class1.java. Compile and run Class1. What is the output?
public Class1() {
ic = new InnerClass1();
}
1
static public void main(String[] args) {
Class1 c1 = new Class1();
c1.displayStrings();
}