<< Chapter < Page Chapter >> Page >
This module contains review questions and answers related to generics, inheritance, and subtypes in Java.

Revised: Wed May 11 18:13:42 CDT 2016

This page is included in the following Books:

Table of Contents


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 Generics, Inheritance, and Subtypes .

This module contains review questions and answers keyed to the material in that document.

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.


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 ************************************************//* Integer and Double are both subclasses ofNumber. Both classes define a method named doubleValue that returns the encapsulatednumeric value as type double. */public class Q01{ public static void main(String[]args){ Foo<Integer>iFoo = new Foo<Integer>(15); System.out.println(iFoo.get().doubleValue());Foo<Double>dFoo = new Foo<Double>(1.0/3); System.out.println(dFoo.get().doubleValue());}//end main }//end class Q01//=============================================// class Foo<T extends Number>{ private T obj;public Foo(T obj){ this.obj = obj;}//end constructor public T get(){return obj; }//end get}//end Foo //=============================================//
Figure 1 - Question 1.
15.0 0.3333333333333333

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.Frame; import javax.swing.JInternalFrame;import java.awt.Container; /*Frame and JInternalFrame are both subclasses of Container. Both classes define a constructorthat accepts a String as a title. Both classes define a method named getTitle that returns thetitle string. */public class Q02{ public static void main(String[]args){ Foo<Frame>fFoo = new Foo<Frame>( new Frame("Frame title"));System.out.println(fFoo.get().getTitle()); Foo<JInternalFrame>jFoo = new Foo<JInternalFrame>( new JInternalFrame("JInternalFrame title")); System.out.println(jFoo.get().getTitle());}//end main }//end class Q02//=============================================// class Foo<T extends Container>{ private T obj;public Foo(T obj){ this.obj = obj;}//end constructor public T get(){return obj; }//end get}//end Foo //=============================================//

Questions & Answers

hello, I am happy to help!
Shirley Reply
please can go further on polynomials quadratic
I need quadratic equation link to Alpa Beta
Abdullahi Reply
find the value of 2x=32
Felix Reply
divide by 2 on each side of the equal sign to solve for x
Want to review on complex number 1.What are complex number 2.How to solve complex number problems.
use the y -intercept and slope to sketch the graph of the equation y=6x
Only Reply
how do we prove the quadratic formular
Seidu Reply
hello, if you have a question about Algebra 2. I may be able to help. I am an Algebra 2 Teacher
Shirley Reply
thank you help me with how to prove the quadratic equation
may God blessed u for that. Please I want u to help me in sets.
what is math number
Tric Reply
x-2y+3z=-3 2x-y+z=7 -x+3y-z=6
Sidiki Reply
Need help solving this problem (2/7)^-2
Simone Reply
what is the coefficient of -4×
Mehri Reply
the operation * is x * y =x + y/ 1+(x × y) show if the operation is commutative if x × y is not equal to -1
Alfred Reply
An investment account was opened with an initial deposit of $9,600 and earns 7.4% interest, compounded continuously. How much will the account be worth after 15 years?
Kala Reply
lim x to infinity e^1-e^-1/log(1+x)
given eccentricity and a point find the equiation
Moses Reply
12, 17, 22.... 25th term
Alexandra Reply
12, 17, 22.... 25th term
A soccer field is a rectangle 130 meters wide and 110 meters long. The coach asks players to run from one corner to the other corner diagonally across. What is that distance, to the nearest tenths place.
Kimberly Reply
Jeannette has $5 and $10 bills in her wallet. The number of fives is three more than six times the number of tens. Let t represent the number of tens. Write an expression for the number of fives.
August Reply
What is the expressiin for seven less than four times the number of nickels
Leonardo Reply
How do i figure this problem out.
how do you translate this in Algebraic Expressions
linda Reply
why surface tension is zero at critical temperature
I think if critical temperature denote high temperature then a liquid stats boils that time the water stats to evaporate so some moles of h2o to up and due to high temp the bonding break they have low density so it can be a reason
Need to simplify the expresin. 3/7 (x+y)-1/7 (x-1)=
Crystal Reply
. After 3 months on a diet, Lisa had lost 12% of her original weight. She lost 21 pounds. What was Lisa's original weight?
Chris Reply
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!

Source:  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.

Notification Switch

Would you like to follow the 'Object-oriented programming (oop) with java' conversation and receive update notifications?