JavaDailyReports10_07
动手动脑①

1 package test_1;
2
3 public class Test {
4
5 public static void main(String[] args) {
6 // TODO 自动生成的方法存根
7 Foo obj1=new Foo();
8 Foo obj2=new Foo();
9 System.out.println(obj1==obj2);
10 }
11 }
12 class Foo{
13 int value=100;
14 }

动手动脑②:类字段的初始化顺序:
1 package test_1;
2
3 public class Test {
4
5 public static void main(String[] args) {
6 // TODO 自动生成的方法存根
7 InitializeBlockClass obj=new InitializeBlockClass();
8 System.out.println(obj.getField());
9
10 obj=new InitializeBlockClass(300);
11 System.out.println(obj.getField());
12 }
13 }
14 class InitializeBlockClass{
15
16 {
17 setField(200); //代码块定义值是200
18 }
19 private int field=100; //定义初始值是 100
20 InitializeBlockClass(int value) { //传入参数是300
21 this.setField(value);
22 }
23 InitializeBlockClass() {
24 }
25 public int getField() {
26 return field;
27 }
28 public void setField(int field) {
29 this.field = field;
30 }
31 }

1 package test_1;
2
3 public class Test {
4
5 public static void main(String[] args) {
6 // TODO 自动生成的方法存根
7 InitializeBlockClass obj=new InitializeBlockClass();
8 System.out.println(obj.getField());
9
10 obj=new InitializeBlockClass(300);
11 System.out.println(obj.getField());
12 }
13 }
14 class InitializeBlockClass{
15 private int field=100; //定义初始值是 100
16 {
17 setField(200); //代码块定义值是200
18 }
19
20 InitializeBlockClass(int value) { //传入参数是300
21 this.setField(value);
22 }
23 InitializeBlockClass() {
24 }
25 public int getField() {
26 return field;
27 }
28 public void setField(int field) {
29 this.field = field;
30 }
31 }

1 package test_1;
2
3 class Root
4 {
5 static
6 {
7 System.out.println("Root的静态初始化块");
8 }
9
10 {
11 System.out.println("Root的普通初始化块");
12 }
13
14 public Root()
15 {
16 System.out.println("Root的无参数的构造器");
17 }
18 }
19 class Mid extends Root
20 {
21 static
22 {
23 System.out.println("Mid的静态初始化块");
24 }
25 {
26 System.out.println("Mid的普通初始化块");
27 }
28 public Mid()
29 {
30 System.out.println("Mid的无参数的构造器");
31 }
32 public Mid(String msg)
33 {
34 //通过this调用同一类中重载的构造器
35 this();
36 System.out.println("Mid的带参数构造器,其参数值:" + msg);
37 }
38 }
39 class Leaf extends Mid
40 {
41 static
42 {
43 System.out.println("Leaf的静态初始化块");
44 }
45 {
46 System.out.println("Leaf的普通初始化块");
47 }
48 public Leaf()
49 {
50 //通过super调用父类中有一个字符串参数的构造器
51 super("Java初始化顺序演示");
52 System.out.println("执行Leaf的构造器");
53 }
54
55 }
56
57 public class TestStaticInitializeBlock
58 {
59 public static void main(String[] args)
60 {
61 new Leaf();
62
63
64 }
65 }
规律总结:
一个父类后继承两个子类,调用顺序为:总顺序先static代码块后普通代码块 最后构造代码块,先父类后子类,先无参构造,后带参构造!
*****************************************************
动手动脑④:

1 package test_1;
2
3 public class StaticStudy {
4 static int staticnum=1;
5 private int num;
6 public static void display() {
7 StaticStudy test=new StaticStudy();
8 System.out.println("在静态方法中输出静态变量:"+test.staticnum);
9 System.out.println("在静态方法中输出非静态变量:"+test.num);
10 }
11 public int getNum() {
12 return num;
13 }
14 public void setNum(int num) {
15 this.num = num;
16 }
17 public StaticStudy(int num) {
18 this.num = num;
19 }
20 public StaticStudy() {
21
22 }
23 public static void main(String[] args) {
24 // TODO 自动生成的方法存根
25 StaticStudy test0=new StaticStudy(100);
26 test0.display();
27 }
28
29 }

//只需要在静态变量里实例化一个本类的对象,通过这个对象取用本对象的数据成员!
动手动脑⑤:
Java中的包装类
1 package test_1;
2
3 public class StrangeIntegerBehavior
4 {
5 public static void main(String[] args)
6 {
7 Integer i1=100;
8
9 Integer j1=100;
10
11 System.out.println(i1==j1);
12
13 Integer i2=129;
14
15 Integer j2=129;
16
17 System.out.println(i2==j2);
18
19 }
20 }


-128 --- 127 范围内是相等的,超出范围一定会重新生成对象!所以地址值就会不同!
JavaDailyReports10_07的更多相关文章
随机推荐
- 创建实验楼课程app模块以及配置图片路径
1.创建course模型 1.1 创建用户模型course python ../manage.py startapp course # 创建course模型 1.2 在setting.py中注册cou ...
- fist-第七天冲刺随笔
这个作业属于哪个课程 https://edu.cnblogs.com/campus/fzzcxy/2018SE1 这个作业要求在哪里 https://edu.cnblogs.com/campus/fz ...
- docker镜像无法删除 Error:No such image:xxxxxx
前言 docker镜像无法删除,通过 docker images 查看镜像明明存在就是删除不了. 删除提示:Error:No such image:xxxxxxx 具体截图内容如下: 解决方法 进入目 ...
- Jmeter介绍、下载及配置
Jmeter介绍: Apache JMeter是Apache组织开发的基于Java的压力测试工具.最初被设计用于Web应用测试,后来扩展到其他测试领域. 它可以用于测试静态和动态资源,例如静态文件.J ...
- IAR编译出现Configuration is up-to-date.
IAR编译出现如下: Building configuration: SimpleBLECentral - CC2541EM Updating build tree... Configuration ...
- node-sass版本问题
node-sass sass-loader的问题 出现了版本的问题 版本太高 版本不兼容解决方法: cnpm i node-sass@4.14.1 cnpm i sass-loader@7.3.1 - ...
- PyQt(Python+Qt)学习随笔:QTableWidgetItem项whatsThis、toolTip、statusTip提示信息访问方法
老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 QTableWidget表格部件的QTableWidgetItem项提示信息包括工具栏提示.状态栏提 ...
- 《Machine Learning in Action》—— Taoye给你讲讲Logistic回归是咋回事
在手撕机器学习系列文章的上一篇,我们详细讲解了线性回归的问题,并且最后通过梯度下降算法拟合了一条直线,从而使得这条直线尽可能的切合数据样本集,已到达模型损失值最小的目的. 在本篇文章中,我们主要是手撕 ...
- XSS挑战赛(4)
16-20关 第十六关 关键代码为: <?php ini_set("display_errors", 0); $str = strtolower($_GET["ke ...
- DVWA SQL Injection High
High 虽然是high等级,但是通过源码审计发现与low等级一样,没有对传入的值做任何过滤,唯一不同的就是点击连接后打开了另外一个对话框,用户在新打开的页面输入 其余的步骤与low级别的一样:htt ...
