Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
4th Edition
ISBN: 9780134787961
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
Expert Solution & Answer
Book Icon
Chapter 17, Problem 1MC
Program Description Answer

When instantiating a generic class, only reference type arguments are passed to the type parameters.

Hence, the correct answer is option “B”.

Expert Solution & Answer
Check Mark

Explanation of Solution

Reference types only:

  • Only non-primitive types can be substituted for type parameters when creating instances for generic class.
  • Reference types are non-primitive types.
  • The compiler autoboxes the primitive type values to reference types.

Explanation for incorrect options:

a. Primitive types only:

When creating instances for a generic class, only non-primitive types can be substituted for type parameters.

Hence, the option “A” is wrong.

c. Interface types only:

The type parameters can be specified as interface type but the arguments passed to type parameters at the time of instantiation, must be real types such as Integer, String, and so on.

Hence, the option “C” is wrong.

d. Primitive, reference, and interface types:

When creating instances for a generic class, only reference types can be substituted for type parameters.

Hence, the option “D” is wrong.

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
3. The interface Range is defined below:public interface Range{ void setLimits(int x, int y); int getNumber();} Implementations of Range should exhibit the following behaviour:• The setLimits method should store its parameter values somewhere to serve as the lower and upper limits of the range appropriately.• A call to getValue should return an integer that is always greater than or equal to the lower limit and less than or equal to the upper limit.The class RandomInteger is an implementation of the interface Range. It also has the following features:• It has two fields of int type, low and high, to record the lower and upper limits of the range, respectively.• It has single constructor method that takes two integers and stores them in the appropriate fields. Note: You should make use of the setLimits method.• A call to the method getNumber should return a random number that is always within the range, i.e. greater than or equal to the lower limit and less than or equal to the upper…
TRUE OR FALSE A method that uses a generic class parameter can be static or dynamic.
The interface Range is defined below:public interface Range{ void setLimits(int x, int y); int getNumber();}Implementations of Range should exhibit the following behaviour:• The setLimits method should store its parameter values somewhere to serve as the lower and upper limits of the range appropriately.• A call to getValue should return an integer that is always greater than or equal to the lower limit and less than or equal to the upper limit.The class RandomInteger is an implementation of the interface Range. It also has the following features:• It has two fields of int type, low and high, to record the lower and upper limits of the range, respectively.• It has single constructor method that takes two integers and stores them in the appropriate fields. Note: You should make use of the setLimits method.• A call to the method getNumber should return a random number that is always within the range, i.e. greater than or equal to the lower limit and less than or equal to the upper limit.…

Chapter 17 Solutions

Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)

Ch. 17.3 - Prob. 17.11CPCh. 17.3 - Prob. 17.12CPCh. 17.3 - Prob. 17.13CPCh. 17.3 - Prob. 17.14CPCh. 17.4 - Prob. 17.15CPCh. 17.5 - Prob. 17.16CPCh. 17.5 - Prob. 17.17CPCh. 17.6 - Prob. 17.18CPCh. 17.6 - Prob. 17.19CPCh. 17.6 - Prob. 17.20CPCh. 17.8 - Prob. 17.21CPCh. 17.8 - Prob. 17.22CPCh. 17.9 - Prob. 17.23CPCh. 17.9 - During the process of erasure, when the compiler...Ch. 17.9 - Prob. 17.25CPCh. 17 - Prob. 1MCCh. 17 - Prob. 2MCCh. 17 - Look at the following method header: void...Ch. 17 - Look at the following method header: void...Ch. 17 - Look at the following method header: void...Ch. 17 - Look at the following method header: void...Ch. 17 - Prob. 7MCCh. 17 - Prob. 8MCCh. 17 - Prob. 9MCCh. 17 - The process used by the Java compiler to remove...Ch. 17 - True or False: It is better to discover an error...Ch. 17 - Prob. 12TFCh. 17 - True or False: Type parameters must be single...Ch. 17 - Prob. 14TFCh. 17 - Prob. 15TFCh. 17 - True or False: You cannot create an array of...Ch. 17 - Prob. 17TFCh. 17 - Prob. 18TFCh. 17 - Prob. 1FTECh. 17 - Assume the following is a method header in a...Ch. 17 - public class MyClassT { public static void...Ch. 17 - public class PointT extends Number super Integer {...Ch. 17 - Assume there is a class named Customer. Write a...Ch. 17 - Assume names references an object of the...Ch. 17 - Prob. 3AWCh. 17 - Prob. 4AWCh. 17 - Prob. 5AWCh. 17 - Prob. 6AWCh. 17 - Prob. 7AWCh. 17 - Prob. 1SACh. 17 - Look at the following method header: public T...Ch. 17 - Prob. 3SACh. 17 - Do generic types exist at the bytecode level?Ch. 17 - Prob. 5SACh. 17 - When the compiler encounters a class, interface,...Ch. 17 - Prob. 1PCCh. 17 - Prob. 2PCCh. 17 - Prob. 3PCCh. 17 - Prob. 4PCCh. 17 - Prob. 5PCCh. 17 - Prob. 6PCCh. 17 - Prob. 7PC
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
  • Text book image
    Microsoft Visual C#
    Computer Science
    ISBN:9781337102100
    Author:Joyce, Farrell.
    Publisher:Cengage Learning,
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,