Questions
The program
Problem.java
doesn't compile. What do you need to do to make it compile? Why?Use the Java API documentation for the
Box
class (in thejavax.swing
package) to help you answer the following questions.What static nested class does
Box
define?What inner class does
Box
define?What is the superclass of
Box
's inner class?Which of
Box
's nested classes can you use from any class?How do you create an instance of
Box
'sFiller
class?
Exercises
Get the file
Class1.java
. Compile and runClass1
. What is the output?The following exercises involve modifying the class
DataStructure.java
, which the section Inner Class Example discusses.Define a method named
print(DataStructureIterator iterator)
. Invoke this method with an instance of the classEvenIterator
so that it performs the same function as the methodprintEven
.Invoke the method
print(DataStructureIterator iterator)
so that it prints elements that have an odd index value. Use an anonymous class as the method's argument instead of an instance of the interfaceDataStructureIterator
.Define a method named
print(java.util.Function<Integer, Boolean> iterator)
that performs the same function asprint(DataStructureIterator iterator)
. Invoke this method with a lambda expression to print elements that have an even index value. Invoke this method again with a lambda expression to print elements that have an odd index value.Define two methods so that the following two statements print elements that have an even index value and elements that have an odd index value:
DataStructure ds = new DataStructure() // ... ds.print(DataStructure::isEvenIndex); ds.print(DataStructure::isOddIndex);
'Java 배우기' 카테고리의 다른 글
Questions and Exercises: Enum Types (0) | 2016.01.05 |
---|---|
Enum Types 이넘 타입 (0) | 2016.01.05 |
When to Use Nested Classes, Local Classes, Anonymous Classes, and Lambda Expressions (0) | 2016.01.05 |
Method References (0) | 2016.01.05 |
Lambda Expressions 람다 표현식 (0) | 2016.01.05 |
댓글