Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (1)
master
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
The license selected for the repository is subject to the license used by the main branch of the repository.
master
Branches (1)
master
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (1)
master
java-code
/
test_3
/
test_3.java
java-code
/
test_3
/
test_3.java
test_3.java 2.65 KB
Copy Edit Raw Blame History
zding404 authored 2022年04月03日 21:40 +08:00 . 测试_3 继承关系的详解
public class test_3 {
public static void main(String[] args) {
Son son = new Son(); //创建子类对象
//创建的过程:
//1).在执行到上面代码(new)时,会先向上查找父类信息,且会一直找到Object类为止
//2).找到Object类后,会先开始加载Object类信息,然后再加载GrandPa类的信息
// 再然后加载Father类的信息,最后才加载Son类的信息
// 加载的具体过程:
// a.在new时,会在堆中创建第一个内存空间
// b.第一个内存空间会用来加载Object类
// c.然后会在第一个内存空间后面创建第二个内存空间
// d.第二个内存空间会用来加载Grandpa类
// 其中,Grandpa类里有name和hobby两个String属性,而这两个属性值会
// 在方法区中的常量池里开辟两个空间分别进行存放,并将这两个
// 内存空间的地址存放到堆中的第二个内存空间里分别表示Grandpa类
// 的两个属性
// e.再然后会在第二个内存空间后面创建第三个内存空间
// f.第三个内存空间会用来加载Father类
// 其中,Father类里有一个String类型的name和nt类型的age两个属性
// name属性的值会在方法区中的常量池里开辟一个内存空间进行存放,并
// 将这个内存空间的地址存放到堆中的第三个内存空间里来表示Grandpa类
// 的name的属性
// age属性的值会直接在堆中第三个内存空间中存放
// g.最后会在第三个内存空间后面创建第四个内存空间
// h.第三个内存空间会用来加载Son类
// 其中,Son类里有一个String类型的name属性
// name属性的值会在方法区中的常量池里开辟一个内存空间进行存放,并
// 将这个内存空间的地址存放到堆中的第三个内存空间里来表示Grandpa类
// 的name的属性
//
// <<所以,即便父类和子类的属性名是一样的,也不会报错>>
//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
//这里又会有一个问题?
//当父类和子类的属性名一样时,我们要如何去访问对应类的属性呢?
//这里要按照查找关系来返回信息
//1).首先看子类是否有该信息
//2).如果子类有这个属性,并且可以访问,则返回这个子类的属性信息
//3).如果子类没有这个属性就看父类有没有这个属性(如果有,并且
// 可以访问,就返回父类的信息)
//4).一直按照3).的规则查找上级父类,直到Object
//5).如果找到了,但不可一访问,则报错
//6).如果直到Object都没有找到,则报错
System.out.println(son.hobby);
}
}
class GrandPa{ //爷类
String name = "大头爷爷";
String hobby = "下棋";
}
class Father extends GrandPa{ //父类
String name = "大头爸爸";
int age = 46;
}
class Son extends Father{ //子类
String name = "小头儿子";
}
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

About

Cancel

Releases

No release

Contributors

All

Language(Optional)

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/Meguminn0/java-code.git
git@gitee.com:Meguminn0/java-code.git
Meguminn0
java-code
JavaCode
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /