static方法的使用注意
2013-03-16 15:58
183 查看
1.static方法不能直接调用非static的field 和方法
2.static方法可以用实例.方法或变量的形式来调用非static方法或变量
public class StaticDemon{
int i = 100;
public static void main(String[] args){
StaticDemon sd = new StaticDemon();
sd.test(sd.i);
}
static void main1(){
StaticDemon sd = new StaticDemon();
sd.test(sd.i);
}
void test(int i){
}
}
2.static方法可以用实例.方法或变量的形式来调用非static方法或变量
public class StaticDemon{
int i = 100;
public static void main(String[] args){
StaticDemon sd = new StaticDemon();
sd.test(sd.i);
}
static void main1(){
StaticDemon sd = new StaticDemon();
sd.test(sd.i);
}
void test(int i){
}
}
相关文章推荐
- JAVA8接口中的default、static方法使用注意事项
- Java8接口中default、static方法使用注意事项
- C/C++ static使用方法注意
- (20)static用法、特点、与非静态的区别、使用注意事项、利弊、什么时候用、对主函数的理解、对已封装好的类方法调用的理解
- JAVA8接口中的default、static方法使用注意事项
- JAVA8接口中的default、static方法使用注意事项
- reset是js的方法,在jquery中使用应注意
- mysql中使用存储过程方法中的注意事项
- OC学习笔记11--protocol使用方法及注意事项
- iPhone SDK中多线程的使用方法以及注意事项
- C++中Static作用和使用方法
- Stust2的拦截器的运行流程及使用方法、注意事项
- 建立和使用包含static方法的对象类型
- 由static关键字引发的知识点学习和在类中的使用相关注意事项
- jquery中ajax方法使用json需注意的小问题
- 使用String.split方法时要注意的问题
- android SoundPool调用pause stop方法使用注意问题
- java4android(5)面向对象、类的定义、生成对象的方法、使用对象的方法、生成多个对象、构造函数super()、函数重载、static、继承
- android使用代码生成LayerDrawable的方法和注意事项
- PHP中$_FILES的使用方法及注意事项说明