关于Java中静态变量和静态方法的问题 谁能给我讲讲java中静态方法和静态变量的含义和使用方法,谢了~~~ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 java中静态方法和静态变量你理解为类方法和类变量就可以了,也就是说只要有类对象存在,你就可以调用其类方法,而不用生命一个对象才能调用。 静态变量和方法基本可以理解为类变量和类方法 另外就是静态的东西创建后只在JVM里面保存了一个唯一的副本... 静态方法就是不用new对象,直接用 Object.method()就可以用! public class Test1 { public static final String MY_STR = "test"; public static String test(){ String str = MY_STR; //非静态变量在静态方法中不能访问return str; } }public class Test2 { public String test(){ String str = "test"; return str; } } public class Test { public static void main(String args[]){ Test2 test2 = new Test2(); String str2 = test2.test(); String str1 = Test1.test();String str3 = Test1.MY_STR ;} } 在SWT中加入tomcat的控制台,有人会吗? 弱弱的想请问一下有关io流的。。 JButton 如何解决:[Microsoft][SQLServer JDBC Driver]Unhandled data type: TDS_INT8 (100分求助)java实现文件检索转换功能 中文显示问题! 俺不明白什么时候适合使用静态内部类? applet 怎样访问数据库? 关于剪贴板(对象的复制、粘贴,而非String的复制、粘贴) 有关JBuilder的,很急。 我的聊天界面,怎么写才能完成两端通信呢? 100分求java经典笔试题(分不够还可以加)
public static final String MY_STR = "test";
public static String test(){
String str = MY_STR; //非静态变量在静态方法中不能访问
return str;
}
}public class Test2 {
public String test(){
String str = "test";
return str;
}
} public class Test {
public static void main(String args[]){
Test2 test2 = new Test2();
String str2 = test2.test(); String str1 = Test1.test();
String str3 = Test1.MY_STR ;
}
}