没有合适的资源?快使用搜索试试~ 我知道了~
java中静态与非静态的变量定义与使用
4星 · 超过85%的资源 需积分: 49 23 下载量 174 浏览量
2010-03-21
20:00:07
上传
评论 1
收藏 23KB DOC 举报
温馨提示
试读
2页
在Java中定义变量时需要慎重考虑是静态还是非静态,因为静态拥有绝对优先权!
资源推荐
资源详情
资源评论
package 静态与非静态;
class Bow1{
Bow1(int maker){
System.out.println("Bow1("+maker+")");
}
void f(int maker){
System.out.println("f("+maker+")");
}
}
class Table{
static Bow1 b1=new Bow1(1);
Table(){
// System.out.println("Table("+")");
System.out.println("Table()");
b2.f(1);
}
void f2(int maker){
System.out.println("f2("+maker+")");
}
static Bow1 b2=new Bow1(2);
}
class Cupboard{
Bow1 b3=new Bow1(3);
static Bow1 b4=new Bow1(4);
Cupboard(){
System.out.println("Cupboard()");
b4.f(2);
}
void f3(int maker){
System.out.println("f3("+maker+")");
}
static Bow1 b5=new Bow1(5);
}
public class Main {
public static void main(String[] args) {
System.out.println("Creating new Cupboard("+")in main");
new Cupboard();
System.out.println("Creating new Cupboard("+")in main");
new Cupboard();
t2.f2(1);
c1.f3(1);
}
资源评论
- 另一个名字2013-11-12还是挺不错的
mozhixi
- 粉丝: 3
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功