火虎

导航

c#关于继承类的一些特性

今天看见了c#中关于继承类的一些问题:
using System;
public class person{
 public void name()
 {
  Console.Write("Person");
 }
}

public class student:person{
  public void name1()
  {
   Console.Write("Student");
  }
 }
public class test{
 public static void Main(){
  person p=new person();
  person s=new student();
  p.name();
//s.name1();
  if(s is student)
   Console.WriteLine("\nok");
   Console.ReadLine();
 }
}
如果你把注释行去掉的话,你就会发现报错,虽然s是一个student类,但是它却没有student的方法,因为它的声明是一个person类,这确实是挺奇怪的一件事.......
不知道为什么vc

posted on 2005-11-20 22:28  firetiger  阅读(607)  评论(2)    收藏  举报