接口如何调用对象类方法? [英] How Interfaces are calling Object class methods?

查看:225
本文介绍了接口如何调用对象类方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们都知道接口不是类,因此接口不继承任何类,甚至不继承对象类.

但是,当我们在一个类中实现一个接口并覆盖该类中的对象类方法时,则可以从该接口调用子类中重写的对象类方法(通过接口引用变量).

接口如何调用子类的个人方法?

请回答..........

We all know Interfaces are not classes and so interfaces do not inherit any class and even do not inherit object class.

But when we Implement a interface in a class and override the object class method in that class, then we can call that object class method overridden in our child class from the interface(by interface reference variable).

How can interface call personal methods of child class?

Answer Please..........

推荐答案

当您说ImyInterface obj = new ImplementedClass()时,obj实际上指向了ImpletedCalss对象的引用实例,因此它能够访问对象上的方法.
when you say ImyInterface obj = new ImplementedClass(), obj is actually pointing to the reference of ImpletedCalss object instance on the heap and hence it is able to access the method on the object.


回答后续问题:

没有个人方法"之类的东西.可以通过类型转换调用它.不能仅由于运行时类型不确切而直接调用它,而是已知它的类型为System.Object.

—SA
Answering the follow-up question:

There is no such thing as "personal method". It can be called, via type cast. It cannot be called directly only because the run-time type is not known exactly, but it''s known that it is of the type System.Object.

—SA


这篇关于接口如何调用对象类方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆