当前位置:网站首页>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():调用父类的构造
.
边栏推荐
- 文献综述怎么写 ,一直没头绪写不出来怎么办?
- Use Base64 to show pictures
- oracle中遇到的bug
- The era of copilot free is over! The official version is 67 yuan / month, and the student party and the defenders of popular open source projects can prostitute for nothing
- laravel8 beanstalk 使用说明
- STM32F1与STM32CubeIDE编程实例-红外寻迹传感器驱动
- 构建信创产业生态,移动云立足全栈自主创新连放大招
- beanstalk 常用方法、说明
- On shore experience of Chang'an University majoring in transportation in 2023
- 文件IO(1)
猜你喜欢

Typora set up image upload service

Nuxt.js spa与ssr的区别

The era of copilot free is over! The official version is 67 yuan / month, and the student party and the defenders of popular open source projects can prostitute for nothing
![[GXYCTF2019]BabySQli](/img/51/a866a170dd6c0160ce98d553333624.png)
[GXYCTF2019]BabySQli

Copilot免费时代结束!正式版67元/月,学生党和热门开源项目维护者可白嫖

Go string comparison
![[geek Challenge 2019] hardsql](/img/73/ebfb410296b8e950c9ac0cf00adc17.png)
[geek Challenge 2019] hardsql
![[geek challenge 2019] hardsql](/img/73/ebfb410296b8e950c9ac0cf00adc17.png)
[geek challenge 2019] hardsql

Three implementation methods of distributed lock
![[GYCTF2020]Blacklist](/img/a8/0f7231e5c498e6c89ff2e3bcb122f2.png)
[GYCTF2020]Blacklist
随机推荐
Find minimum in rotated sorted array
Notes on using the coding code base
mysql乐观锁与悲观锁
Dr. Sun Jian was commemorated at the CVPR conference. The best student thesis was awarded to Tongji Ali. Lifeifei won the huangxutao Memorial Award
同花顺推荐么?手机开户安全么?
[极客大挑战 2019]HardSQL
马斯克 18 岁儿子请愿改名,欲断绝父子关系
Install using snap in opencloudos NET 6
JS教程之 什么是 JSX?为什么我们需要它?
XML related interview questions
[geek Challenge 2019] hardsql
IPv6 的速度比 IPv4 更快?
Three methods to find the limit of univariate function -- lobida's rule and Taylor's formula
[plugin:vite:import-analysis]Failed to resolve import “@/“ from ““.Does the file exist
必须知道的RPC内核细节(值得收藏)!!!
Gesture recognition based on mediapipe
给RepVGG填坑?其实是RepVGG2的RepOptimizer开源
谷贱伤农,薪贱伤码农!
[wangdingbei 2020 Qinglong formation]areuserialz
2021-04-12 链表第一次实现!!!