当前位置:网站首页>2021-05-07封装 继承 super this
2021-05-07封装 继承 super this
2022-06-23 09:55:00 【鹿其其鹿】
封装
高内聚 低耦合
属性私有 get/set
封装的意义:
提高程序的安全性,保护数据
隐藏代码的实现细节
统一接口
系统可维护性增加
继承
继承的本质是对某一批类的抽象,从而实现对现实世界更好的建模
extends的意思是扩展,子类是父类的扩展
java类中只有单继承,没有多继承
子类继承父类,使用关键字extends来表示
//Person 人 父类
public class Person {
public void say(){
System.out.println("说了一句话");
}
}
package oop.demo5;
//学生 is 人 子类
public class Student extends Person{
}
public class Application {
public static void main(String[]args){
Student student = new Student();
student.say();
}
}
私有的东西无法被继承(除非用get,set提取)
super 注意点
- super调用父类的构造方法,必须在构造方法的第一个
- super必须只能出现在子类的方法或者构造方法中
- super和this不能同时调用构造方法
super VS this
代表的对象不同:
this:本身调用者这个对象
super:代表父类对象的应用
前提:
this:没有继承也可以使用
super:只能在继承条件下才可以使用
构造方法:
this():调用本类的构造
super():调用父类的构造
.
边栏推荐
- 多线程习题
- 给RepVGG填坑?其实是RepVGG2的RepOptimizer开源
- Nuxt.js spa与ssr的区别
- Gorm 高级查询
- What is BFC? What problems can BFC solve
- Unity技术手册 - 形状(Shape)子模块 - Sprite、SpriteRenderer及生命周期内速度(Velocity over Lifetime)
- Wechat applet: click the button to switch frequently, overlap the custom markers, but the value does not change
- RBtree
- 太阳塔科技招聘PostgreSQL数据库工程师
- 卧槽,最惊艳的论文神器!
猜你喜欢

sql编写问题,求出当月和上月的环比值

SQL教程之SQL 中数据透视表的不同方法

数学分析_笔记_第2章:实数与复数

卧槽,最惊艳的论文神器!
![[plugin:vite:import-analysis]Failed to resolve import “@/“ from ““.Does the file exist](/img/1f/dde52dc63de58d67f51161e318a9fb.png)
[plugin:vite:import-analysis]Failed to resolve import “@/“ from ““.Does the file exist

Pet Feeder Based on stm32

Dr. Sun Jian was commemorated at the CVPR conference. The best student thesis was awarded to Tongji Ali. Lifeifei won the huangxutao Memorial Award

Go string comparison

RPC kernel details you must know (worth collecting)!!!

薄膜干涉数据处理
随机推荐
Jump game of leetcode topic analysis
RT-Thread 添加 msh 命令
135,137,138,445禁用导致无法远程连接数据库
[極客大挑戰 2019]HardSQL
表单重复提交问题
[ciscn2019 North China Day2 web1]hack world
mysql innodb 的 redo log buffer 中未 commit 的事务持久化到 redo log 后,万一事务 rollback 了怎么办?redo log 怎么处理这个事务操作?
Unity技术手册 - 生命周期内速度限制(Limit Velocity Over Lifetime)子模块和速度继承(Inherit Velocity)子模块
Bioinformatics | effective drug target correlation prediction based on interacting neural network
[plugin:vite:import-analysis]Failed to resolve import “@/“ from ““.Does the file exist
J. Med. Chem. | RELATION: 一种基于靶标结构的深度学习全新药物设计模型
Servlet-02 lifecycle
文献综述怎么写 ,一直没头绪写不出来怎么办?
Difference between global shutter and roller shutter
thymeleaf如何取url中请求参数值?
Mysql database introduction summary
薄膜干涉数据处理
Go 字符串比较
2021-05-11抽象类
Pet Feeder Based on stm32