You work as a developer at ABC.com. The ABC.com network consists of a single domain named
ABC.com.
You have been tasked with creating an application that manages product data. You have written
the code shown below:
Public static void Save<T>(T target) where T : Product
{
}
Which of the following is TRUE with regards to this code? (Choose all that apply.)
A.
It allows for the Save() method to be strongly typed.
B.
It prevents the Save() method from being strongly typed.
C.
It allows all types regardless of inheritance.
D.
It only allows types inherited from the Product class that makes use of a constructor that
accepts no parameters.
Explanation:
Option A
A and D
D because “T:Product” means that generic Type T used here as method’s parameter of Save, inherited from Product
Option A
D : that makes use of a constructor that accepts no parameters
==>
Public static void Save(T target) where T : Product, new()
{
}
A only
Are you sure about A only
Why is D also correct ? there is no new() here.
Please correct an answer, it should be A only. Jonathan is absolutely correct
Only A is the correct answer. If the question was “where T : Product, new()”, it would be A and D.
A) only
if D) is true
the Save methode should be like :
public static void Save(T target) where T : Product, new()
{
}