This page is optimized for mobile devices, if you would prefer the desktop version just click here

8.6 Java4260r: review of type inference

This module contains review questions and answers related to generic type inference in Java.

Revised: Wed May 11 18:23:25 CDT 2016

This page is included in the following Books:

Table of Contents

Preface

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 Type Inference . This module contains review questions and answers keyed to the material in thatdocument.

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 to make it easy for you to navigate from the question to the answer and back again.

Note that much of the type inference material discussed in this module requires the use of Java SE 7 or a later version.

Questions

Question 1 .

True or False: The code shown in Listing 1 will compile and run successfully producing the output shown in Figure 1 .

Listing 1 - Question 1.
/*File Q01.java ************************************************/import java.awt.*; /*Note the following inheritance hierarchyjava.lang.Object java.awt.Componentjava.awt.Container java.awt.Windowjava.awt.Frame */public class Q01{ public static void main(String[]args){ Foo<Window>var = new Foo<Window>(); var.runIt();}//end main }//end class Q01//=============================================// class Foo<T extends Component>{ public void runIt(){System.out.println("Object instantiated."); }//end runIt}//end Foo
Figure 1 - Question 1.
Object instantiated.

Answer 1

Question 2

True or False: The code shown in Listing 2 will compile and run successfully producing the output shown in Figure 2 .

Listing 2 - Question 2.
/*File Q02.java ************************************************/import java.awt.*; /*Note the following inheritance hierarchyjava.lang.Object java.awt.Componentjava.awt.Container java.awt.Windowjava.awt.Frame */public class Q02{ public static void main(String[]args){ Foo<Window>var = new Foo<>(); var.runIt();}//end main }//end class Q02//=============================================// class Foo<T extends Component>{ public void runIt(){System.out.println("Object instantiated."); }//end runIt}//end Foo
<< Chapter < Page Page > Chapter >>

Read also:

OpenStax, Object-oriented programming (oop) with java. OpenStax CNX. Jun 29, 2016 Download for free at https://legacy.cnx.org/content/col11441/1.201
Google Play and the Google Play logo are trademarks of Google Inc.
Jobilize.com uses cookies to ensure that you get the best experience. By continuing to use Jobilize.com web-site, you agree to the Terms of Use and Privacy Policy.