Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
Question 1: The programProblem.java
doesn't compile. What do you need to do to make it compile? Why?
Answer 1: Addfinal
in front of the declaration of thetimer
variable. 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 theBox
class (in thejavax.swing
package) to help you answer the following questions.a. What static nested class doesBox
define?
Answer 2a:Box.Filler
b. What inner class doesBox
define?
Answer 2b:Box.AccessibleBox
c. What is the superclass ofBox
s inner class?
Answer 2c:[java.awt.]Container.AccessibleAWTContainer
d. Which ofBox
s nested classes can you use from any class?
Answer 2d:Box.Filler
e. How do you create an instance ofBox
sFiller
class?
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.java
that defines subclasses of bothClass1
and its inner class,InnerClass1
. (Call the subclassesClass2
andInnerClass2
, respectively.)InnerClass2
should override thegetAnotherString
method to return"InnerClass2 version of getAnotherString invoked"
.Class2
should define one constructor and one method:
- A no-argument constructor that initializes the inherited
ic
instance variable to be an instance ofInnerClass2
- A main method that creates an instance of
Class2
and invokesdisplayStrings
on 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.