Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

HELP Generics are important to Java because they enable the creation of code tha

ID: 3808895 • Letter: H

Question

HELP

Generics are important to Java because they enable the creation of code that is

a: Type-safe , b:Reusable, C: Reliable, D:all the above.

Can a primitive type be used as a type argument?

Yes, if the argument has more than one parameter

b.Yes, only primitive type can be used as a type argument

c. No, type argument must be object types

Show how to declare a class called FlightSched that takes two generic parameters.

a.class FlightSched<>{T, V},

class FlightSched(V, T) {

c.class FlightSched<generic, Integers> {

d.class FlightSched<T, V> {

Can the wildcard argument be bounded?

a.Yes, a wild card must have a lower bound only

b.Yes, a wild card must have an upper bound only

c.No, a wild card argument cannot be bounded.

d.Yes, a wild card can have either an upper or lower bound

.Do type parameters exist at run time?

a.No, some type parameters are erased during runtime

b.No, all type parameters are erased during compliation, and appropriate casts are substituted

c.Yes, all type parameters exist at run time

interface,

polymorphism

inheritance

none of the above ?

a.

Yes, if the argument has more than one parameter

Explanation / Answer

1. Generics are important to Java because they enable the creation of code that is

A. Type-safe

B. Reusable

C. Reliable

D. All of the above

Answer: D. All of the above

Can a primitive type be used as a type argument?

Yes, if the argument has more than one parameter

b.Yes, only primitive type can be used as a type argument

c. No, type argument must be object types

d.Yes, type argument does not have to be object types

Answer : c. No, type argument must be object types

Show how to declare a class called FlightSched that takes two generic parameters.

a.class FlightSched<>{T, V},

b.

class FlightSched(V, T) {

c.class FlightSched<generic, Integers> {

d.class FlightSched<T, V> {

Answer : d.class FlightSched<T, V> {

Can the wildcard argument be bounded?

a.Yes, a wild card must have a lower bound only

b.Yes, a wild card must have an upper bound only

c.No, a wild card argument cannot be bounded.

d.Yes, a wild card can have either an upper or lower bound

Answer : Yes, a wild card can have either an upper or lower bound

.Do type parameters exist at run time?

a.No, some type parameters are erased during runtime

b.No, all type parameters are erased during compliation, and appropriate casts are substituted

c.Yes, all type parameters exist at run time

d.No, all type parameters are erased during runtime, and appropriate casts are substituted

Answer : b.No, all type parameters are erased during compliation, and appropriate casts are substituted

All methods in an abstract class must be decalred as abstract methods

true/false ? False - An abstract class is a class that is declared abstract —it may or may not include abstract methods.

Invoking a subclass-only method through a subclass variable is not allowed

true/false ? false

If a superclass declares an abstract method, a subclass must implement that method.

true/false? true

An object of a class that implements an interface may be thought of as an object of that interface type

true/false? true

An annotation is syntactically based on a/an: Interface

a.

Yes, if the argument has more than one parameter