The following two small test questions are collected from the Internet. If you are interested, try them,
Do not compile the test results first. Answer the following according to your feelings:
1. There is such a class:
Class t
{
Protected string AAA;
Public T (string Val)
{AAA = val ;}
Public String getstring (T)
{Return T. AAA ;}
}
And the following usage:
1 ):
T T1 = new T ("test ");
Console. writeline (t1.getstring (T1 ));
2 ):
T T1 = new T ("test1 ");
T t2 = new T ("Test2 ");
Console. writeline (t1.getstring (T2 ));
Select the answer and explain the reason:
A) compilation fails.
B) The first method cannot pass
C) The second method fails.
D) can pass
Ii. Write the results output by the Console
Using System;
Class Base
{
Private Int M = 2 ;
Public Int Getm (Child C)
{
Return C. m;
}
Public IntGetm (Base B)
{
ReturnB. m;
}
PublicBase ()
{}
PublicBase (IntM)
{
This. M=M;
}
}
class child: base
{< br> private int m = 1 ;< br> Public New int getm (Child C)
{< br> return C. m;
}
PublicChild (IntM ):Base(M)
{This. M= 4;}
}
Class Test
{
Public Static Void Main ()
{
Base B = New Base ();
Child C = New Child ( 3 );
Console. writeline (B. getm (c ));
Console. writeline (C. getm (c ));
Console. writeline (B. getm (base) c ));
}
}
Interesting question. However, I think it is not very easy to do the second question. You can guess the result and compile the test again.