不用编辑器,回复你的答案~~
到处闲逛,看到两个前年的帖子,还真琢磨了一会的~~发上来给大家品品~~
要求:不用编辑器,回复你的答案,不带赖皮的哇~~
第一部分
1.
- C# code
using System; class A { public virtual void Foo() { Console.WriteLine("Call on A.Foo()"); } } class B : A { public virtual void Foo() { Console.WriteLine("Call on B.Foo()"); } } class C : B { public override void Foo() { Console.WriteLine("Call on C.Foo()"); } } class D { static void Main() { A c1 = new C(); c1.Foo(); Console.ReadLine(); } }
2.
- C# code
using System; class A { public virtual void Foo() { Console.WriteLine("Call on A.Foo()"); } } class B : A { public override void Foo() { Console.WriteLine("Call on B.Foo() " ); } } class C : B { public new void Foo() { Console.WriteLine("Call on C.Foo()"); } } class D { static void Main() { A c1 = new C(); c1.Foo(); Console.ReadLine(); } }
3.
- C# code
using System; class A { public virtual void Foo() { Console.WriteLine("Call on A.Foo()"); } } class B : A { public virtual new void Foo() { Console.WriteLine("Call on B.Foo() " ); } } class C : B { public override void Foo() { Console.WriteLine("Call on C.Foo()"); } } class D { static void Main() { A c1 = new C(); c1.Foo(); Console.ReadLine(); } }
无耻分割线
===========================================
第二部分:
1.
- C# code
interface IGrandFather { void F(); } class Father:IGrandFather { public void F() { Console.WriteLine("\nFather."); } } class Children:Father { public new void F() { Console.WriteLine("\nChildren."); } } class Test { public static void Main(string[] args) { IGrandFather gf = new Children(); gf.F(); } }
2.
- C# code
interface IGrandFather { void F(); } class Father:IGrandFather { public virtual void F() { Console.WriteLine("\nFather."); } } class Children:Father { public override void F() { Console.WriteLine("\nChildren."); } } class Test { public static void Main(string[] args) { IGrandFather gf = new Children(); gf.F(); } }
3.
- C# code
interface IGrandFather { void F(); } class Father:IGrandFather { public virtual void F() { Console.WriteLine("\nFather."); } } class Children:Father { public void F(string arg) { Console.WriteLine("\nChildren:{0}",arg); } } class Test { public static void Main(string[] args) { IGrandFather gf = new Children(); gf.F(); } }
4.
- C# code
interface IGrandFather { void F(); } abstract class Father:IGrandFather { public void F() { Console.WriteLine("\nFather."); } } class Children:Father { public void F() { Console.WriteLine("\nChildren."); } } class Test { public static void Main(string[] args) { IGrandFather gf = new Children(); gf.F(); } }
5.
- C# code
interface IGrandFather { void F(); } abstract class Father:IGrandFather { public virtual void F() { Console.WriteLine("\nFather."); } } class Children:Father { public void F() { Console.WriteLine("\nChildren:{0}"); } } class Test { public static void Main(string[] args) { IGrandFather gf = new Children(); gf.F(); Console.ReadLine(); } }
6.
- C# code
interface GrandFather { void F(); } class Father:GrandFather { public void F() { Console.WriteLine("\nFather."); } } class Children:Father,GrandFather { public new void F() { Console.WriteLine("\nChildren"); } } class Test { public static void Main(string[] args) { GrandFather gf = new Children(); gf.F(); Console.ReadLine(); } }
7.
- C# code
using System; class A { public virtual void F(string p) { Console.WriteLine(p); } } class B:A { public void F(ref string p) { Console.WriteLine("ref:"+p); } } class Test { public static void Main(string[] args) { string s = "xxxx"; B b = new B(); b.F(s); b.F(ref s); } }
结果是次要的 原理是重要的.
[解决办法]
还没大看,晚上有时间的
[解决办法]
[解决办法]
嘿嘿!看看,学习下
[解决办法]
经常被这个搞的晕乎乎的,楼主能帮我解释下第一部分为什么分别是 "Call on C.Foo()" ,"Call on B.Foo()","Call on A.Foo()"吗?谢谢啊
[解决办法]
一堆题目应该只考了两点:
1:非override 显示声明的都归个new
2:string 和ref string 是为重载关系..
[解决办法]
学习,
[解决办法]
学习,
[解决办法]
[解决办法]
呵呵,有点晕。楼主给出答案吧
[解决办法]
1.一直往上找,一直找到他的祖宗
[解决办法]
有override 覆盖祖宗的方法,用他自己的,就考这些知识点
[解决办法]
下班回去看
[解决办法]
mark,等下回来答答看
[解决办法]
mark
[解决办法]
up
[解决办法]
顶
[解决办法]
看不懂。
[解决办法]
up
------解决方案--------------------
顶
[解决办法]
mark 要研究研究
[解决办法]
up
[解决办法]
ding
[解决办法]
Call on C.Foo()
Call on B.Foo()
Call on C.Foo()
Father
Children
Father
Children
Children:{0}
Father
Xxxx
ref: Xxxx
不太明白,猜的。
[解决办法]
没看懂标题
[解决办法]
帮顶
[解决办法]
mark
[解决办法]
不懂
[解决办法]
顶
[解决办法]
太长了
[解决办法]
mark
[解决办法]
学习下!
[解决办法]
饶人的东西
[解决办法]
做记录~!学习
[解决办法]
收藏
[解决办法]
mark 要研究研究
[解决办法]
这题目也太简单了,c#语言规范(ecma334)上面的几个例子更复杂、更全面
[解决办法]
up
[解决办法]
不懂C#
[解决办法]
学习,高人
[解决办法]
mark
[解决办法]
mark 我得运行运行的了
[解决办法]
[解决办法]
学习学习在学习
[解决办法]
控制台输出,初学.net windows编程时,玩过.
[解决办法]
看不明白,高深
[解决办法]
开不懂哦!!
[解决办法]
很简单的哦,只要明白内存运行原理,一看就知道了。;运行原理我还是从学java那里学来的。
[解决办法]
有一次去面试,就有这种题,把我弄晕了。哈哈
[解决办法]
还把new 和 override 弄出来了,好好看书的人都会哦;new 是隐藏父类的虚方法,override是完全覆盖。ref 必须先初始化,out不用初始化,java 中没有这两个关键字,就用类名来代替;睡觉了这两天一直在看基础
[解决办法]
mark