Two compiled test questions collected

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.