类 对象 接口

xiaoxiao2021-02-28  98

类是一组具有相同属性和行为的对象的抽象。 对象模型中的类可以看做是开发人员自定义的数据类型,当调用类是就是把自定义的数据类型映射到计算机内置数据类型的过程,是开发人员不受计算机内置数据类型的限制,对任意一种问题领域,都可以方便地根据显示别对象,再进行分类(创建任意的数据类型)的思路来建立对象模型。 例如相面这个手机类的定义。 public class CellPhone{ private String type; private String color; private int price; /*构造方法*/ public CellPhone(String type, String color, int price) { this.type = type; this.color = color; this.price = price; } /* 打电话*/ public void cell(){} /*照相*/ public void takePhoto(){} /*发送信息*/ public void sendMessage(){} }

在现实世界中,接口也是实体,比如电源插口、洗衣机上的按钮和电灯的开关。在面向对象中,接口是一个抽象的概念,是指系统对外提供的所有服务.每个对象都是服务提供者,因此每个对象都有接口。

CellPhone type; color; price; {takePhoto() call() }手机的接口

转载请注明原文地址: https://www.6miu.com/read-61798.html

最新回复(0)