面试——面向对象题

    一:抽象类与接口的区别(用英文描述)
   Interface is open to the public, there can not have the private methods and variables.It is used to let others use, but the abstract class can have private  methods or private variables.In addition, the realization of the interface must be realized in the interface definition of all methods, and the realization  of the abstract category have the choice of rewriting need to use the method, the general application, is the top of the interface, and then to achieve an  abstract category Interface, and finally to achieve specific category. Furthermore, the interface can be achieved multiple inheritance, a class can only  inherit a super-category, but can be inherited through multiple interface multiple inheritance, the interface is also available logo (There are no any way,  such as the Remote Interface) and data Sharing (there are all the variables constant) role.
   中文:
  接口是公开的,里面不能有私有的方法或变量,是用于让别人使用的,而抽象类是可以有私有方法或私有变量的,

另外,实现接口的一定要实现接口里定义的所有方法,而实现抽象类可以有选择地重写需要用到的方法,一般的应用里,最顶级的是接口,然后是抽象类实现接口,最后才到具体 类实现。

还有,接口可以实现多重继承,而一个类只能继承一个超类,但可以通过继承多个接口实现多重继承,接口还有标识(里面没有任何方法,如Remote接口)和数据共享(里面的变 量全是常量)的作用.

  二:struct与类的区别   struct值传递
类与结构有很多相似之处:结构可以实现接口,并且可以具有与类相同的成员类型。然而,结构在几个重要方面不同于类:结构为值类型而不是引用类型,并且结构不支持继承。结构的值存储在“在堆栈上”或“内联”。细心的程序员有时可以通过聪明地使用结构来增强性能。

 三.概述反射和序列化
反射:程序集包含模块,而模块包含类型,类型又包含成员。反射则提供了封装程序集、模块和类型的对象。您可以使用反射动态地创建类型的实例,将类型绑定到现有对象,或从现有对象中获取类型。然后,可以调用类型的方法或访问其字段和属性
序列化:序列化是将对象转换为容易传输的格式的过程。例如,可以序列化一个对象,然后使用 HTTP 通过 Internet 在客户端和服务器之间传输该对象。在另一端,反序列化将从该流重新构造对象。

 四.如何理解委托?
答:据说相当于函数指针,定义了委托就可以在不调用原方法名称的情况下调用那个方法.
msdn2005中是这样解释的:
委托具有以下特点:
委托类似于 C++ 函数指针,但它是类型安全的。
委托允许将方法作为参数进行传递。
委托可用于定义回调方法。
委托可以链接在一起;例如,可以对一个事件调用多个方法。
方法不需要与委托签名精确匹配。有关更多信息,请参见协变和逆变。

posted on 2008-06-25 16:38  prayforsmile  阅读(1049)  评论(0编辑  收藏  举报