当前位置:网站首页>2022-07-26 group 4 abstract classes and interfaces
2022-07-26 group 4 abstract classes and interfaces
2022-07-27 08:05:00 【Self cultivation class】
abstract
abstract
Abstract methods do not have braces , There is no method body
The significance of abstract methods
Fundamental significance , Appointment : Custom rules
Agreed return value , Access right , parameter list ,, Need to rewrite , Restart the first method
Convention over configuration , Configuration is greater than encoding
Abstract methods must be in an abstract class
When we define an abstract class , What structures can there be in this abstract class
attribute , Member method , Constructors , Abstract method , Constant
Can there be no abstract methods in an abstract class
Sure
Abstract classes cannot be instantiated
Abstract classes cannot be created objects
The significance of the existence of constructors of abstract classes :
In order to agree that the constructor of a subclass must match the parent class
If a class inherits an abstract class , You must override all abstract methods of this abstract class
abstract What can be modified ?
class 、 Method .
summary : The abstract method must be public and protected
Abstract classes cannot be instantiated directly , You need to rely on subclasses to handle it in an upward transformation way
Abstract classes must have subclasses , Use extends Inherit , A class can only inherit one abstract class
Subclass ( If it's not an abstract class ) You must rewrite all abstract methods in the class
( If the subclass does not implement the abstract method of the parent class , Subclasses must be defined as abstract)
Interface
More advanced abstractions than abstract classes
Abstract classes are also more advanced than classes
Statement : Use interface keyword
Only abstract methods can be defined in an interface , Cannot have attributes , There can't be a way .
( You can put static constants and static methods 、 The default method )
Characteristics of the structure in the interface :
Methods in the interface default to public
The structure in the interface must be public
Interfaces can be implemented
If a class implements an interface , It needs to rewrite all methods of the interface
The meaning of interfaces :
Appointment
java There are multiple inherited , Occurs between interfaces
There is single inheritance between classes
Anonymous implementation class
public class Ch01 {
public static void main(String[] args) {
Abstr01 abstr01=new Abstr01() {
public void show(){
System.out.println(" rewrite show Method ");
}
};
abstr01.show();
}
}
边栏推荐
- PHP realizes data interaction with MySQL
- JS存取cookie示例
- Convert objects to key value pairs
- Internet of things industrial UART serial port to WiFi to wired network port to Ethernet Gateway WiFi module selection
- DEMO:ST05 找文本ID 信息
- How to log in multiple wechat on the computer
- slf4j如何进行logback配置呢?
- 容器内使用sudo报错bash: sudo: command not found解决
- Stored procedure test 1 -- first acquaintance of love
- 【目标检测】YOLOv6理论解读+实践测试VisDrone数据集
猜你喜欢
![[resolved] SSO forwarding succeeded, and there was an unexpected error (type=internal server error, status=500) caused by parameters in the forwarding URL](/img/05/41f48160fa7895bc9e4f314ec570c5.png)
[resolved] SSO forwarding succeeded, and there was an unexpected error (type=internal server error, status=500) caused by parameters in the forwarding URL

杂谈:手里有竿儿,肩上有网,至于背篓里有多少鱼真的重要吗?

The dragon lizard exhibition area plays a new trick this time. Let's see whose DNA moved?

如何更新pip3?和Running pip as the ‘root‘ user can result in broken permissions and conflicting behaviour

Demo submit a program and obtain ALV data of the program

Promise details

Demo:st05 find text ID information

北京五日游记

浅谈数据安全

2020 International Machine Translation Competition: Volcano translation won five championships
随机推荐
Demo:pa30 Bank Country Code default CN enhancement
[ten thousand words long article] thoroughly understand load balancing, and have a technical interview with Alibaba Daniel
Solid smart contract development - 3.3-solid syntax control structure
数据提取2
File name wildcard rules for kettle
[applet] the upload of the wechat applet issued by uniapp failed error: error: {'errcode': -10008,'errmsg':'Invalid IP
数据提取1
API version control [eolink translation]
DEMO SUBMIT 某程序并获取该程序ALV数据
Grandson's questions are difficult, and his son's invigilation is strict. I can't do it. Pay back my school money
What other methods are available for MySQL index analysis besides explain
Zero training platform course-1. SQL injection Foundation
C language: random number + Hill sort
反弹shell是什么?反弹shell有什么用?
Shell Scripts相关
Why do major domestic manufacturers regard cloud computing as a pastry? Do you really understand this trillion market
slf4j如何进行logback配置呢?
[flight control development foundation tutorial 4] crazy shell · open source formation UAV - serial port (optical flow data acquisition)
Enhancement: BTE process introduction
Framework of electronic mass production project -- basic idea