1 Star 0 Fork 2

Wings/JavaProgramming

forked from tzhanggit/JavaProgramming 
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
StaticInitialization.java 1.21 KB
一键复制 编辑 原始数据 按行查看 历史
TZhangOffice 提交于 2020-06-06 16:20 +08:00 . 2020春代码更新完毕
package ch5.testStatic;
/**
* 1. static variables
* վ̬ʼ˳
*/
class Bowl {
Bowl(int i) { System.out.println("Bowl(" + i + ")"); }
void f1(int i) { System.out.println("f1(" + i + ")"); }
}
class Table {
static Bowl bowl1 = new Bowl(1);
Table() {
System.out.println("Table()");
bowl2.f1(1);
}
void f2(int i) { System.out.println("f2(" + i + ")"); }
static Bowl bowl2 = new Bowl(2);
}
class Cupboard {
Bowl bowl3 = new Bowl(3);
static Bowl bowl4 = new Bowl(4);
Cupboard() {
System.out.println("Cupboard()");
bowl4.f1(2);
}
void f3(int i) { System.out.println("f3(" + i + ")"); }
static Bowl bowl5 = new Bowl(5);
}
public class StaticInitialization {
public static void print(int x, int y) {
}
public static void main(String[] args) {
System.out.println("new Cupboard() in main");
new Cupboard();
System.out.println("new Cupboard() in main");
new Cupboard();
table.f2(1);
cupboard.f3(1);
StaticInitialization.print(1, 2);
Math.abs(-5);
}
static Table table = new Table();
static Cupboard cupboard = new Cupboard();
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/wingszeng/JavaProgramming.git
git@gitee.com:wingszeng/JavaProgramming.git
wingszeng
JavaProgramming
JavaProgramming
master

搜索帮助