接口和类对象之间的区别 [英] Difference between interface and class objects

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

问题描述

我正在阅读Oracle文档,但没有得到任何帮助.

I'm reading through the Oracle doc, but I don't get something.

假设我有

public interface a {
    //some methods
}
public class b implements a {
    //some methods
}

这有什么区别?

a asd=new b();

和这个:

b asf=new b();

推荐答案

没有这样的东西.至少不能编译.

There is no such thing. At least not compile.

a asd=new a(); // you can't instantiate an interface

b asf=new a(); // you can't instantiate an interface

您可以执行以下操作.

b asd=new b();  

a asd=new b(); 

这篇关于接口和类对象之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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