当前位置:网站首页>What is an abstract class
What is an abstract class
2022-08-10 10:53:00 【heart move】
Event address: CSDN 21-day Learning Challenge
I. What is an abstract class?
Class – a custom composite data type used to describe a set of things with common properties
Create a java class with the class keyword.
Java classes decorated with abstract are abstract classes.
Format: access modifier abstract class class name{}
Example:
public abstract class Hello{ }
Second, why use abstract classes?
The emergence of abstract classes reflects the refactoring of java. [Extracted repeated actions]
Abstract classes provide a general form that can be shared by subclasses, and subclasses handle this general form according to their actual situation.
For example: take a car to charge, taxis have a charging function [1 yuan/km], and buses have a charging function [1 yuan for the whole journey]
Subclasses of abstract classes are often the same thing.
4. What elements can be included in an abstract class?
Element instance variables, class variables, construction methods, instance methods, class methods, [abstract methods] in abstract classes.
Abstract method – abstract modification, a method without a method body.
An abstract method is the general form that an abstract class provides to subclasses.
An abstract class can have abstract methods or none at all.Ordinary java classes cannot have abstract methods.
For example

Three, the specific usage of abstract class
1. Abstract class cannot be new
2. Ordinary java class inherits abstract class, it needs to rewrite the abstract method in the abstract class, otherwise the ordinary java classThe class is changed to an abstract class.
3. Abstract classes can inherit other abstract classes without overriding abstract methods.
4. Create an abstract class object using the upcast object.
5. An abstract class object can access instance variables, class variables, construction methods, instance methods, class methods, [abstract methods] in the abstract class.
6. When an abstract class object accesses an abstract method, it actually accesses the abstract method after the subclass rewrites it.
7. When the method parameter in a common java class is an abstract class type, the upcast object can be passed, or it can be a subclass object of the abstract class.



边栏推荐
猜你喜欢
随机推荐
Redis6(一)——NoSQL数据库简介与Redis的安装
ESP8266 Tutorial 1 - Introduction to ESP8266 Hardware Platform
Redis (three) - detailed configuration file, publish and subscribe, new data types
Dialogue with Chen Ciliang: Nezha wants to popularize high-end products
chart.js水平柱状图插件
Text selection rounded style border-radius
【Redis】Redis入门教程(介绍 下载安装 Jedis 图形化界面)
跨公网环境,路由策略,进行设备的访问
what is bsp in rtems
[C language] Header file #include
, conio is Console Input/Output (console input and output) 2022.8.7-----leetcode.636
3D rotating text animation js special effects
LeetCode Algorithm 1721. 交换链表中的节点
OSSCore 开源解决方案介绍
2022.8.8-----leetcode.761
3D旋转文本动画js特效
MySQL 执行查询流程
PPT | 「课件」企业中高层人员安全管理培训(118页)
【物联网架构】什么是物联网平台?
Redis(三)——配置文件详解、发布和订阅、新数据类型








