当前位置:网站首页>Abstract classes and interfaces (sorting out some knowledge points)
Abstract classes and interfaces (sorting out some knowledge points)
2022-07-27 00:08:00 【Muxi Krystal】
Abstract classes and interfaces
This is what I'm learning 《Java Language programming 》(Y.Daniel Liang) I took notes when I was studying .
1. The parent class defines the common behavior of related subclasses . Interfaces can be used to define the common behavior of classes ( Include unrelated classes ).
2. Abstract classes cannot be used to create objects . An abstract class can contain abstract methods , These methods will be implemented in specific subclasses .
3. occasionally , A parent class is designed to be very abstract , So that it has no specific examples . Such a class is called abstract class .
public abstract class GeometricObject {
private String color = "white";
private boolean filled;
private java.util.Date dateCreated;
/** Construct a default geometric object */
protected GeometricObject() {
dateCreated = new java.util.Date();
}
/** Construct a geometric object with color and filled value */
protected GeometricObject(String color, boolean filled) {
dateCreated = new java.util.Date();
this.color = color;
this.filled = filled;
}
/** Return color */
public String getColor() {
return color;
}
/** Set a new color */
public void setColor(String color) {
this.color = color;
}
/** Return filled. Since filled is boolean, * the get method is named isFilled */
public boolean isFilled() {
return filled;
}
/** Set a new filled */
public void setFilled(boolean filled) {
this.filled = filled;
}
/** Get dateCreated */
public java.util.Date getDateCreated() {
return dateCreated;
}
/** Return a string representation of this object */
public String toString() {
return "created on " + dateCreated + "\ncolor: " + color +
" and filled: " + filled;
}
/** Abstract method getArea */
public abstract double getArea();
/** Abstract method getPerimeter */
public abstract double getPerimeter();
}
4. A class containing abstract methods must be declared as an abstract class .
5. The construction method of an abstract class is defined as protected, Because it is only used by subclasses . When creating an instance of a concrete subclass , The constructor of its parent class is called to initialize the data field defined in the parent class .
6. You can define an abstract class that does not contain abstract methods , This kind is used to define the base class of new subclasses .
7. Even if the parent of a subclass is concrete , This subclass can also be abstract .
8. Abstract classes can be used as a data type .
9. Interface Is a structure similar to a class , Contains only constants and abstract methods .
10. You can use interfaces as data types of reference variables or as the result of type conversions .
11. The relationship between classes and interfaces is called Interface inheritance .
12.Java Allow modifiers in interfaces to be ignored .
边栏推荐
- Last week's hot review (7.11-7.17)
- Part II - C language improvement_ 11. Pretreatment
- 04-传统的Synchronized锁
- 2022.7.18-----leetcode.749
- The basic operation of data tables in MySQL is very difficult. This experiment will take you through it from the beginning
- Typesript generic constraint
- Force deduction 155 questions, minimum stack
- Galaxy securities online account opening commission, is online account opening safe for customer managers
- Method of realizing program startup and self startup through registry
- 会议OA项目排座功能以及送审功能
猜你喜欢

NFT展示指南:如何展示你的NFT藏品

Azure synapse analytics Performance Optimization Guide (4) -- optimize performance using result set caching

Azure Synapse Analytics 性能优化指南(3)——使用具体化视图优化性能(下)

MVC三层架构
![[netding Cup 2018] Fakebook records](/img/9f/b9111da8b2d9f8e79d82847aec906c.png)
[netding Cup 2018] Fakebook records

NFT display guide: how to display your NFT collection

MVC three-tier architecture

上千Tile的倾斜模型浏览提速,告别一块一块往外蹦的尴尬

Share a regular expression

Transformers is a graph neural network
随机推荐
Meeting OA my meeting
[literature reading] an investigation on hardware aware vision transformer scaling
The attorney general and the director of the national security service of Ukraine were dismissed
MySQL transaction, phantom reading, current reading, snapshot reading related notes
Section 6: introduction to cmake grammar
Distributed lock and its implementation
会议OA项目排座功能以及送审功能
New features of ES6
Question 152: product maximum subarray
第1章 需求分析与ssm环境准备
第二部分—C语言提高篇_6. 多维数组
分页插件--PageHelper
Paging plug-in -- PageHelper
Pytorch学习记录(二):张量
大疆智图、CC生产了多份数据,如何合并为一份在图新地球进行加载
Positioning of soaring problems caused by online MySQL CPU
2022.7.18-----leetcode.749
MVC three-tier architecture
JUnit、JMockit、Mockito、PowerMockito
数据库:MySQL基础+CRUD基本操作