当前位置:网站首页>2022/07/26 learning notes (day16) abstraction and interface
2022/07/26 learning notes (day16) abstraction and interface
2022-07-26 19:44:00 【Radical cucumber】
Catalog
5. Downward transformation between classes and interfaces :
abstract :
1. abstract class :
Concept : Further abstraction of classes , A method without a method body , At the same time, abstract methods must also use keywords abstract Decorate .
2. Grammar format :
Add... Before the return value type abstract
3. Instance object :
step :
1. You can't create abstract class objects directly
2. You must inherit the parent class with a subclass
3. Non Abstract subclasses must override all abstract methods in the overriding Abstract parent class
4. Remove abstract keyword , Fill in the method body braces
5. Create subclass objects for use
4. data type
Reference data type
5. Construction method
Used to call subclasses
6. Abstract method :
Judge :
When it is impossible to determine whether the method body of a method is executed, it is an abstract method
Format :
public abstract void Method name ( );
Conditions :
The class of the abstract method must be an abstract class
Interface :
1. brief introduction :
In the life
Interface is a kind of public standard
stay java in
An interface is a common specification for multiple classes
The most important content is abstract methods
2. Defining interfaces :
Grammar format :
List of modifiers interface The interface name { }
3. Realization :
1. The interface cannot be used directly , There must be an implementation class to implement this interface
Format :
public class Implementation class name implements The name of the interface
2. The implementation class of the interface must override ( Realization ) All abstract methods in the interface
Override override abstract methods
Get rid of abstract keyword , Add method body braces
3. Create objects that implement classes , And use
Be careful :
If the implementation class does not cover all the methods in the interface , Then the implementation class must be an abstract class
4. When inheritance and interface appear at the same time :
extends Keywords before ,implement The key word comes after
5. Downward transformation between classes and interfaces :
In an inheritance relationship :
If there is no inheritance
Compilation failed
There must be an inheritance relationship to transition down
Compile and pass
There may be ClassCastException
Between class and interface :
There is no inheritance relationship can also be transformed downward
Compilation can pass
There may be ClassCastException
6. The transformation of :
Classes and interfaces can be forcibly converted without inheritance :
Premise : This class is an interface
Otherwise ClassCastException
Interfaces can be forcibly transferred without inheritance :
The implementation class pointed to by the interface reference All interfaces for forced conversion should be implemented
Compilation and operation can pass
The implementation class pointed to by the interface reference Not all interfaces for forced conversion are implemented
Compilation can pass , Run appears ClassCastException abnormal
7. Content :
Abstract method :
Be careful :
Abstract methods in interfaces , Modifier must be public abstract Two fixed keywords
These two modifiers , You can optionally omit ( Not recommended for beginners )
The three elements of the method can be defined at will
Constant :
Format :
public static final constant type Constant names = Face value ;
Naming specification :
All letters are capitalized , Each word is separated by an underscore
Be careful :
public static final It can be omitted
Constants in the interface , Assignment must be made. , You can't do without assignment
There is no way to construct
Be careful :
Interfaces cannot have static method blocks and constructor
Multiple inheritance
A class can only have one parent , But a class can implement multiple interfaces
If there are multiple interfaces implemented in the implementation class , There are repetitive abstract methods , Then you only need to cover it once
If the implementation class does not cover all abstract methods , Then the implementation class must be an abstract class
In inheritance, there must be an inheritance relationship to compile in order to pass ( Static binding )
Mind mapping :
abstract :
Interface :

边栏推荐
- C # upper computer development - modify the window icon and exe file Icon
- Save 50% of the cost JD cloud releases a new generation of hybrid CDN products
- 周末看点回顾|数字人民币产业联盟成立;中国移动宣布:和飞信将停止服务…
- 带你熟悉云网络的“电话簿”:DNS
- Redis介绍
- Deeply analyze the execution process of worker threads in the thread pool through the source code
- Is qiniu a channel for securities companies? Is it safe to open an account?
- Leetcode-138-copy linked list with random pointer
- TB 117-2013 US Federal mandatory regulations
- eadiness probe failed: calico/node is not ready: BIRD is not ready: Error querying BIRD: unable to c
猜你喜欢
随机推荐
UIAutomator2常用类之UiObject2
Linear algebra Chapter 3 vector
手机app测试用例怎么写?手机app测试点有哪些?
Uiobject2 of uiautomator2 common classes
JS中的 作用域
2022/07/26 学习笔记 (day16) 链表和栈
Design of intelligent weighing system based on Huawei cloud IOT (STM32) [II] there is information at the end
torch. Usage and comparison of unsqueeze() squeeze() expand() repeat()
canvas概述
Image preview embedding location of blog maintenance record
IM即时通讯开发如何压缩移动网络下APP的流量消耗
Leetcode daily practice - 88. Merge two ordered arrays
论文精读:YOLOV2——YOLO9000:Better, Faster, Stronger
NLP learning path
6种方法帮你搞定SimpleDateFormat类不是线程安全的问题
How to protect e-commerce websites from network attacks?
C#上位机开发—— 修改窗口图标和exe文件图标
EN 1504-7 products for protection and repair of concrete structures corrosion prevention of reinforcement - CE certification
Using MySQL master-slave replication delay to save erroneously deleted data
拿铁DHT-PHEV产品响当当,销量会不会让李瑞峰想通了呢?







