this关键字在继承中的使用
2024-09-17 11:54:11
参考:http://blog.csdn.net/gxzzxj/article/details/51946144
下面是自己的代码:
public class ChildA extends Father {
void add() {
System.out.println("A中的ADD");
}
}
public class ChildB extends Father {
void add() {
System.out.println("B中的ADD");
}
}
import org.apache.catalina.filters.AddDefaultCharsetFilter; public class Father {
public Father() {
System.out.println(this);
}
void add() {
System.out.println("父类中的ADD");
} }
public class Main {
public static void main(String[] args) {
Father a = new ChildA();
a.add();
}
}
参考博客的代码及结果
public class Father1 {
private int a = 10; Father1() {
System.out.println(this instanceof Son);
System.out.println(this.a);
System.out.println(((Son) this).a);
System.out.println(this.getClass().getName());
} public static void main(String[] args) { Father1 s = new Son();
System.out.println(s.a);
}
}
class Son extends Father1 {
public int a = 0;
public int b = 1;
public Son() {
//隐式调用super();
super();
System.out.println("Son类中执行:"+this);
} }
最新文章
- UVALive 4998 Simple Encryption --DFS
- Spring 下载与安装以及spring 3.2.9 jar包详解
- (转)SQL Server 的事务和锁(一)
- Extjs的radio单选框的使用
- NOIP200304麦森数
- CSS笔记(十三)CSS3之过渡
- DCL_数据库控制语言
- 函数fold 或reduce用法
- 【百度地图API】如何进行地址解析与反地址解析?——模糊地址能搜索到精确地理信息!
- Save Update saveOrUpdate delete
- 关于S/4HANA里Sales Office 和Sales Organization那些事儿
- Linux内核编译时会遇到的问题--缺少mkimage
- docker php容器中简单添加seaslog拓展
- Spring事务的传播:PROPAGATION_REQUIRED
- Linux下源码安装xz的方法
- JavaWeb过滤器.监听器.拦截器-原理&;区别(转)
- Maven环境配置及简单使用(二)
- jsonp 接口
- FireDAC 下的 Sqlite [3] - 获取数据库的基本信息
- MySQL数据库服务器整体规划(go)
热门文章
- 【postgresql】postgresql中的between and以及日期的使用
- how to avoid over-fitting?(机器学习中防止过拟合的方法,重要)
- [NPM] Set default values for package.json using npm set
- Android自己定义View基础篇(三)之SwitchButton开关
- Servlet的部署开发细节以及注意事项
- PHP读取excel(6)
- 【第四篇章-android平台MediaCodec】解决Observer died. Quickly, do something, ... anything...
- 诊断并解决 ORA-4030 错误 (Doc ID 1548826.1)
- Django-配置celery
- 距特征之k阶距概念