当前位置:网站首页>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():调用父类的构造
.
边栏推荐
- JSP getting started summary
- 数值计算方法
- 【CTF】 2018_rop
- Install using snap in opencloudos NET 6
- Successful experience of postgraduate entrance examination in materials and Chemical Engineering (metal) of Beijing University of Aeronautics and Astronautics in 2023
- High performance computing center Infiniband overview
- Lu Qi invests in quantum computing for the first time
- mysql乐观锁与悲观锁
- Gorm 高级查询
- 2021-04-15
猜你喜欢
![[GYCTF2020]Blacklist](/img/a8/0f7231e5c498e6c89ff2e3bcb122f2.png)
[GYCTF2020]Blacklist

分布式锁的三种实现方式

Install the typescript environment and enable vscode to automatically monitor the compiled TS file as a JS file

J. Med. Chem. | RELATION: 一种基于靶标结构的深度学习全新药物设计模型

XML related interview questions
![[ciscn2019 North China Day2 web1]hack world](/img/bf/51a24fd2f9f0e13dcd821b327b5a00.png)
[ciscn2019 North China Day2 web1]hack world

Gorm 高级查询

Go 字符串比较

Unity技术手册 - 生命周期内速度限制(Limit Velocity Over Lifetime)子模块和速度继承(Inherit Velocity)子模块

构建信创产业生态,移动云立足全栈自主创新连放大招
随机推荐
2021-04-12 the first implementation of linked list!!!
AI系统前沿动态第38期:谷歌已放弃TensorFlow?;训练大模型的四种GPU并行策略;LLVM之父:模块化设计决定AI前途
2022 Gdevops全球敏捷运维峰会-广州站精华回放(附ppt下载)
Comic | code review is driving me crazy!
On shore experience of Chang'an University majoring in transportation in 2023
马斯克 18 岁儿子请愿改名,欲断绝父子关系
Multithreaded exercises
Go 字符串比较
分布式锁的三种实现方式
What is BFC? What problems can BFC solve
STM32F1与STM32CubeIDE编程实例-红外寻迹传感器驱动
在OpenCloudOS使用snap安装.NET 6
薄膜干涉数据处理
构建信创产业生态,移动云立足全栈自主创新连放大招
同花顺是炒股的么?在线开户安全么?
Tencent tangdaosheng: practice "science and technology for the good" and promote sustainable social value innovation
Sun Tower Technology recruits PostgreSQL Database Engineer
给RepVGG填坑?其实是RepVGG2的RepOptimizer开源
文献综述怎么写 ,一直没头绪写不出来怎么办?
[plugin:vite:import-analysis]Failed to resolve import “@/“ from ““.Does the file exist