<< Chapter < Page | Chapter >> Page > |
Revised: Wed May 11 18:05:10 CDT 2016
This page is included in the following Books:
This module is one in a collection of modules on Java Generics designed for teaching ITSE2317 - Java Programming (Intermediate) at Austin Community College in Austin, TX.
This and future modules in this series will be based on the Generics (Updated) section of The Java Tutorials from Oracle. (In the event that these links become broken, you should have no difficulty finding the Oracle material with an online search.)
You will find the learning resources for this module on the Oracle site at:
This module contains review questions and answers keyed to the material in the above listed documents.
Once you study that material, you should be able to answer the review questions in this module.
Once you complete your study of all the material on generics , you should be able to answer the review questions at Questions and Exercises on the Oracle site.
The questions and the answers in this module are connected by hyperlinks tomake it easy for you to navigate from the question to the answer and back again.
True or False: Bounded type parameters are used to restrict the types that can be used as arguments in a parameterized type.
True or False: To declare a bounded type parameter, list the type parameter's name, followed by the extends or implements keyword, followed by its upper bound class or interface.
True or False: A type parameter can have multiple bounds as shown in Figure 1 .
Figure 1 - Question 3. |
---|
<T extends B1&B2&B3> |
True or False: The code shown in Listing 1 will compile and run successfully producing the output shown in Figure 2 .
Listing 1 - Question 4. |
---|
/*File Q04.java
************************************************/import java.awt.*;
/*Note the following inheritance hierarchyjava.lang.Object
java.awt.Componentjava.awt.Container
java.awt.Windowjava.awt.Frame
*/public class Q04{public static void main(String[] args){Foo<Window>aFoo = new Foo<>();
aFoo.runIt();}//end main
}//end class Q04//=============================================//
class Foo<T extends Frame>{
public void runIt(){System.out.println("Object instantiated.");
}//end runIt}//end Foo |
Figure 2 - Question 4. |
---|
Object instantiated. |
Define and write a class named A05Foo which, when combined with the code shown in Listing 2 will produce the output shown in Figure 3 .
Listing 2 - Question 5. |
---|
/*File Q05.java
************************************************/import java.awt.*;
/*Note the following inheritance hierarchyjava.lang.Object
java.awt.Componentjava.awt.Container
java.awt.Windowjava.awt.Frame
*/public class Q05{public static void main(String[] args){A05Foo<Window>aA05Foo = new A05Foo<>();
aA05Foo.runIt();}//end main
}//end class Q05//=============================================// |
Notification Switch
Would you like to follow the 'Object-oriented programming (oop) with java' conversation and receive update notifications?