首页 技术 正文
技术 2022年11月15日
0 收藏 581 点赞 2,787 浏览 901 个字
class Bowl{
Bowl(int marker){
System.out.println("Bowl(" + marker + ")" );
}
void f1(int marker){
System.out.println("f1(" + marker + ")");
}
}class Table{
//首先是静态变量
static Bowl bow1 = new Bowl(1);//2
Table(){
System.out.println("Table()");//4
bowl2.f1(1);//5
}
void f2(int marker){
System.out.println("f2(" + marker + ")");
}
static Bowl bowl2 = new Bowl(2);//3
}class CupBoard{
Bowl bowl3 = new Bowl(3);//8 不是static变量,会与每一个对象绑定,所以每创建一次对象都会初始化一次
static Bowl bowl4 = new Bowl(4);//6
CupBoard(){
System.out.println("CupBoard");//9
bowl4.f1(2);//10
}
static Bowl bowl5 = new Bowl(5);//7
void f3(int marker){
System.out.println("f3(" + marker + ")");
}
}
public class Main {//首先初始化静态变量
public static void main(String[] args) {
System.out.println("Creating new CupBoard in main");
new CupBoard();//11
System.out.println("Creating new CupBoard in main");
new CupBoard();//12
table.f2(1);//13
cupBoard.f3(1);//14
}
static Table table = new Table();//1
static CupBoard cupBoard = new CupBoard();//5
}//顺序:
//首先是静态对象
//非静态对象
//构造函数

  

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,028
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,518
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,366
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,146
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,780
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,858