当前位置:网站首页>Interfaces and Abstractions
Interfaces and Abstractions
2022-07-29 14:24:00 【xiaokaikaa】
文章目录
抽象
在 Java 中,Abstraction can be implemented in two ways 一种是接口,一种是抽象类.
Define methods for interfaces and abstract classes
1.接口
代码如下:
public interface Animal
{
//所有动物都会吃
public void eat();
//所有动物都会飞
public void fly();
}
2.抽象类
代码如下:
public abstract class Animal
{
//所有动物都会吃
public abstract void eat();
//所有动物都会飞
public void fly(){
};
}
It can only be within an interface功能的定义,In abstract classes,Can include the definition of the function and the realization of the function.在接口中,所有的属性肯定是 public、static 和 final,所有的方法都是 abstract,所以可以默认不写上述标识符;在抽象类中,既可以包含抽象的定义,也可以包含具体的实现方法
Implement abstract classes and interfaces
1.实现接口
代码如下:
public class concreteAnimal implements Animal
{
//所有动物都会吃
public void eat(){
}
//所有动物都会飞
public void fly(){
}
}
2.实现抽象类
代码如下:
public class concreteAnimal extends Animal
{
//所有动物都会吃
public void eat(){
}
//所有动物都会飞
public void fly(){
}
}
在接口的实现类中使用 implements 关键字;而在抽象类的实现类中,则使用 extends 关键字.一个接口的实现类可以实现多个接口,而一个抽象类的实现类则只能实现一个抽象类
边栏推荐
- EA&UML日拱一卒-活动图::StartClassifierBehavior和StartObjectBehavior
- 十种实现延迟任务的方案
- 简单了解单例模式
- The core principles of electronic games
- BOM系列之Location对象
- 【Postman】Download and installation (novice graphic tutorial)
- AI全流程开发难题破解之钥
- 进程间通信 --- system V三种通信方式(图文案例讲解)
- 为什么字符串使用final关键字
- What is the difference between the legendary server GOM engine and the GEE engine?
猜你喜欢
随机推荐
FPGA刷题——跨时钟域传输(FIFO+打拍+握手)
R Error in :missing values are not allowed in subscripted assignments of data frames
推荐几款2022年好用的设备管理系统(软件)
根据msql表的结构自动生成gorm的struct
阿里巴巴 CTO 程立:开源是基础软件的源头!
熊市下PLATO如何通过Elephant Swap,获得溢价收益?
计算机专业面试进阶指南
How to Improve Embedded Programming with MISRA
【论文阅读】异常检测的视频通过Self-Supervised和多任务学习
第二轮Okaleido Tiger热卖的背后,是背后生态机构战略支持
479-82(54、11)
尚硅谷大叔培训:揭秘Flink四种执行图——ExecutionGraph和物理执行图
C#实现线程管理类
第4章_3——索引的使用
PHP代码审计得这样由浅入深地学
EA&UML日拱一卒-活动图::Object actions(续)
Children's programming electronics (graphical programming Scratch secondary level exam parsing (choice) in June 2022
Sentinel vs Hystrix 限流到底怎么选?(荣耀典藏版)
1184. 欧拉回路
【10点公开课】:快手GPU/FPGA/ASIC异构平台的应用探索









