惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
T
Threatpost
阮一峰的网络日志
阮一峰的网络日志
美团技术团队
F
Fortinet All Blogs
The GitHub Blog
The GitHub Blog
月光博客
月光博客
V
Visual Studio Blog
T
Tailwind CSS Blog
Stack Overflow Blog
Stack Overflow Blog
博客园 - 聂微东
Jina AI
Jina AI
J
Java Code Geeks
Martin Fowler
Martin Fowler
大猫的无限游戏
大猫的无限游戏
Recorded Future
Recorded Future
C
Check Point Blog
腾讯CDC
N
Netflix TechBlog - Medium
aimingoo的专栏
aimingoo的专栏
罗磊的独立博客
Hacker News: Ask HN
Hacker News: Ask HN
SecWiki News
SecWiki News
博客园 - Franky
Hacker News - Newest:
Hacker News - Newest: "LLM"
N
News | PayPal Newsroom
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Security @ Cisco Blogs
W
WeLiveSecurity
The Last Watchdog
The Last Watchdog
Cloudbric
Cloudbric
F
Full Disclosure
The Cloudflare Blog
Y
Y Combinator Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
S
Schneier on Security
Schneier on Security
Schneier on Security
Spread Privacy
Spread Privacy
L
LINUX DO - 热门话题
AI
AI
N
News and Events Feed by Topic
T
Tor Project blog
P
Palo Alto Networks Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More
G
Google Developers Blog

博客园 - JohnHoo

IE8 报错,问题事件名称:APPCRASH,故障模块名称:StackHash_c4c3 Compiere相关的资料收录 Compiere是什么? 整理的 NBear 中文文档 西安.net俱乐部终于成立了! SQL Server 不存在或访问被拒绝 不能更新。数据库或对象为只读 javascript 调试 恢复IE中出错的FlashGet右键菜单 绝对路径和相对路径 windows server 2003的一些设置 ERP&CRM开源项目(转) TrackBack Test ASCII编码表 收集的一些blog(自己感兴趣的blog,会不断的更新) 无法在web服务器上启动调试,问题解决 无法在WEB服务器上启动调试,一个头痛的问题 十年MFC经历认识的Microsoft技术 dotText WebLog源码分析--开始篇
收集的两个编译的测试题
JohnHoo · 2005-11-18 · via 博客园 - JohnHoo

收集的两个编译的测试题

2005-11-18 17:53  JohnHoo  阅读(542)  评论()    收藏  举报

下面这两个小测试题,从网上收集的,有兴趣的可以试试,

先不要编译测试结果,根据感觉作答:

一:有这样一个类:
                 class T
                 {
                       protected string aaa;

                       public T(string val)
                            {   aaa = val;    }

                       public string GetString(T t)
                            {  return t.aaa;    }
                 }

和以下两种用法:
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));

请选择答案并说明理由:
a) 编译不通过
b)第一种用法不能通过
c)第二种用法不能通过
d)都能通过

二:写出控制台输出的结果

using System; 
class Base 
{
   
private int m=2
   
public int GetM(Child c)
   {
      
return c.m;
   }
public int GetM(Base b)
   {
      
return b.m;
   }
   
   
public Base()
   {}
public Base(int m)
   { 
     
this.m = m; 
   }

class Child : Base 
{
   
private int m=1;
   
public new int GetM(Child c)
   {
     
return c.m;
   }
public Child(int m):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));
   } 
}

很有意思的题目,不过第二题,我觉得不太好做,大家可以先猜猜结果,再去编译测试