关于静态方法问题?????????

friendy 2002-09-03 10:46:14
静态方法除了不需要实例类就可以直接被调用外,其他和非静态方法有什么区别吗?
...全文
19 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
yergrad 2002-09-04
  • 打赏
  • 举报
回复
静态方法不是动态绑定的。即不是在运行时确定执行代码的。
例如
public class STime
{
public static void main(String[] arg)
{
// System.out.println(System.currentTimeMillis());
STime st = new ssTime();
st.testSta();
st.testNoS();
}

static void testSta()
{
System.out.println("STime testSta");
}

void testNoS()
{
System.out.println("STime testNoS");
}
}

class ssTime extends STime
{
static void testSta()
{
System.out.println("ssTime testSta");
}

void testNoS()
{
System.out.println("ssTime testNoS");
}
}
输出结果是:
STime testSta
ssTime testNoS
qxjavajava 2002-09-04
  • 打赏
  • 举报
回复
A static method may only access the static data of its class; it may not access non-static data

A static method may only call the static method of its class; it may not call non-static methods

A static method has no this

A static method may not be overriden to be non-static
friendy 2002-09-04
  • 打赏
  • 举报
回复
这个俺知道,还有其他的吗?
cooleyes 2002-09-04
  • 打赏
  • 举报
回复
在静态方法中不允许调用非静态方法和非静态变量

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧