日期:2014-05-20  浏览次数:20885 次

不用编辑器,回复你的答案~~
到处闲逛,看到两个前年的帖子,还真琢磨了一会的~~发上来给大家品品~~

要求:不用编辑器,回复你的答案,不带赖皮的哇~~


第一部分
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(); 
 } 
}