当前位置:网站首页>2021-05-12 interface definition and Implementation
2021-05-12 interface definition and Implementation
2022-06-23 10:07:00 【Deer like deer】
Interface
General class : Only concrete implementation
abstract class : Specific implementation and specification ( Abstract method ) There are
Interface : Only norms , I can't write by myself - Professional constraints . Constraint and implementation separation : Interface oriented programming
Interface is specification , It defines a set of rules
The essence of an interface is a contract , Like the law , Everyone should abide by
OO The essence of , It's the abstraction of objects , The best way to do this is through interfaces
The keyword of the declaration class is class, Statement The keyword of the interface is interface
package oop.demo11;
//interface Is a defined keyword , Interfaces need to have implementation classes
public interface UserService {
// All definitions in an interface are actually abstract public public It's ok if you don't write
public abstract void run();
void add(String name);
void delete(String name);
void update(String name);
void query(String name);
// The attributes defined in the interface are constants
int age1 = 99;
public static final int age = 99; // be equal to int age1 = 99
}
package oop.demo11;
public interface TimeService {
void timer();
}
// Class passing implements Keyword implementation interface
// The class that implements the interface , Need to rewrite the methods in the interface
// Multiple inheritance , Using interfaces to implement multiple inheritance
public class UserServiceImpi implements UserService,TimeService{
// Multiple inheritance , Inherited UserService and TimeService Two interfaces
@Override
public void run() {
}
@Override
public void add(String name) {
}
@Override
public void delete(String name) {
}
@Override
public void update(String name) {
}
@Override
public void query(String name) {
}
@Override
public void timer() {
}
}
effect :
- constraint ( standard )
- Define some methods , Let different people realize
- public abstract
- public static final
- Interface cannot be instantiated , There is no constructor in the interface
- implements Multiple interfaces can be implemented
- You have to override the methods in the interface
边栏推荐
- Build a security video monitoring platform using Huawei cloud ECS server
- 基于STM32设计的宠物投喂器
- Tencent tangdaosheng: practice "science and technology for the good" and promote sustainable social value innovation
- Unity技术手册 - 形状(Shape)子模块 - Sprite、SpriteRenderer及生命周期内速度(Velocity over Lifetime)
- 多线程习题
- Jog sport mode
- 分布式锁的三种实现方式
- Install the typescript environment and enable vscode to automatically monitor the compiled TS file as a JS file
- regular expression
- Golang 快速上手 (2)
猜你喜欢

J. Med. Chem. | Release: a new drug design model for deep learning based on target structure

Cloud native database Amazon RDS

Bioinformatics | effective drug target correlation prediction based on interacting neural network

基於STM32設計的寵物投喂器

J. Med. Chem. | RELATION: 一种基于靶标结构的深度学习全新药物设计模型

xml相关面试题

文件IO(1)

CVPR大会现场纪念孙剑博士,最佳学生论文授予同济阿里,李飞飞获黄煦涛纪念奖...

陆奇首次出手投资量子计算

Comic | code review is driving me crazy!
随机推荐
搭建一个点歌QQ机器人,另外还能看美女
炫酷相册代码,祝对象生日快乐!
Year end answer sheet! Tencent cloud intelligent comprehensive strength ranks first in China!
After the uncommitted transactions in the redo log buffer of MySQL InnoDB are persisted to the redo log, what happens if the transaction rollback occurs? How does the redo log handle this transaction
How to pass values to onclick events in thymeleaf
Gorm 高级查询
CVPR大会现场纪念孙剑博士,最佳学生论文授予同济阿里,李飞飞获黄煦涛纪念奖...
beanstalk 常用方法、说明
马斯克 18 岁儿子请愿改名,欲断绝父子关系
利用华为云ECS服务器搭建安防视频监控平台
Spring recruitment interview experience summary (technical post)
云原生数据库-Amazon RDS
2021-05-07封装 继承 super this
Typora set up image upload service
卧槽,最惊艳的论文神器!
文献综述怎么写 ,一直没头绪写不出来怎么办?
High performance computing center RDMA implementation technology
mysql innodb 的 redo log buffer 中未 commit 的事务持久化到 redo log 后,万一事务 rollback 了怎么办?redo log 怎么处理这个事务操作?
高性能算力中心 — NVMe/NVMe-oF — NVMe-oF Overview
Bi SQL drop & alter