+ 3
friends can you help me with this question?
Drag and drop from the options below to define a generic class, which has a member method that returns the value of x. Temp { T x; public Func() { x; } } static <x> return x class <T> T
4 ответов
+ 5
Anser:
class Temp<T> {
T x;
public T Func() {
return x;
}
}
+ 2
class<T> //start with "class" and make it generic <T>
{
T x: //define a variable "x" of type T (at this time we don't know the type yet, so we say T
public T Func() //this method returns a value of type T
{
return x; //it returns the variable x that we have declared
} //end of method
}// end of class
static is there to confuse you, it is not needed
<x> is also there to confuse you, it not needed
}
0
I think that is answer of that question of define a generic class, which has a member method that returns the value of x.
Class Temp <T> //generic <T> class
{
T x;
public T Func(){ //generic T method
return x; //return the variable x
}
}
0
Drag and drop from the options below to initialize members in the constructor initializer list, and then print them out in the constructor body: