请前辈谈谈static的机制! static member和static function吗?这个问题就大了。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 简言之,static成员就是由此对象的所有实例共享的成员;static方法是可以不通过对象实例直接调用的方法,其中不可以使用非静态的类成员;还有static内部类呢,Thinking in JAVA里有很好的用法。 //比如:class Test{ static int method1(int x,int y) { return (x+y)*x*y; } public int method2(int x,int y) { return (x-y)*x*y; }}public class TestJava{ public static void main(String [] args) { int m; int n; m=Test.method1(4,6); Test newTest=new Test(); n=newTest.method2(5,3); //NO n=Test.method2(5,3) System.out.println("m = " + m); // m=240 System.out.println("n = " + n); // n=30 }} Linux系统中 JAVA用oracle11g 客户端连接问题 一个jsp页面多个Ec:table问题,在线等!问题解决马上结贴! 谁帮我看下这个程序 编译通过 但是运行出错! JAVA关于行和列名都固定的表格? 环境变量里并没有设置,可是还是能找到路径? 100分在线等,急!!!哪位高手来帮帮? 运行时类型转换 如何用JAVA把ACCESS数据库里的内容转换成到文本中?谢谢 大家说说那种建模工具好? java小程序的疑问 今天上了十几次都是服务器尽快,终于上来的,问一下如何完全从电脑上卸载JVM? 很简单的java程序,求大家帮忙,赚分的好机会!
static方法是可以不通过对象实例直接调用的方法,其中不可以使用非静态的类成员;
还有static内部类呢,Thinking in JAVA里有很好的用法。
class Test
{
static int method1(int x,int y)
{
return (x+y)*x*y;
}
public int method2(int x,int y)
{
return (x-y)*x*y;
}
}public class TestJava
{
public static void main(String [] args)
{
int m;
int n;
m=Test.method1(4,6);
Test newTest=new Test();
n=newTest.method2(5,3); //NO n=Test.method2(5,3)
System.out.println("m = " + m); // m=240
System.out.println("n = " + n); // n=30
}
}