|
|
Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
Question 1: The programProblem.javadoesn't compile. What do you need to do to make it compile? Why?
Answer 1: Addfinalin front of the declaration of thetimervariable. A nested class declared within a method has access to any final, local variables in scope. SeeProblemSolved.java.
Question 2: Use the 5.0 API documentation for theBoxclass (in the
javax.swingpackage) to help you answer the following questions.a. What static nested class doesBoxdefine?
Answer 2a:Box.Fillerb. What inner class doesBoxdefine?
Answer 2b:Box.AccessibleBoxc. What is the superclass ofBoxs inner class?
Answer 2c:[java.awt.]Container.AccessibleAWTContainerd. Which ofBoxs nested classes can you use from any class?
Answer 2d:Box.Fillere. How do you create an instance ofBoxsFillerclass?
Answer 2e:new Box.Filler(minDimension, prefDimension, maxDimension)
Exercise 1: Get the fileClass1.java.
a. Compile and runClass1. What is the output?
Answer 2a:InnerClass1: getString invoked.
InnerClass1: getAnotherString invoked.b. Create a file called
Class2.javathat defines subclasses of bothClass1and its inner class,InnerClass1. (Call the subclassesClass2andInnerClass2, respectively.)InnerClass2should override thegetAnotherStringmethod to return"InnerClass2 version of getAnotherString invoked".Class2should define one constructor and one method:
- A no-argument constructor that initializes the inherited
icinstance variable to be an instance ofInnerClass2- A main method that creates an instance of
Class2and invokesdisplayStringson that instanceWhat is the output when you run
Class2?Answer 2b:
InnerClass1: getString invoked.
InnerClass2 version of getAnother String invoked.See
Class2.java.
|
|
Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
Copyright 1995-2005 Sun Microsystems, Inc. All rights reserved.