类继承的时候报can not resolve symbol,高手指教

dazhi9302 2007-12-08 01:44:54
ack23类继承的时候报can not resolve symbol,symbol ACK...高手指教
代码如下
ACK.JAVA文件
public class ACK
{
int ack(int m,int n)
{
int k;
if (m==0)
k=ack(m-1,1);
else
k=ack(m-1,ack(m,n-1));
return k;
}
ack23.java文件
public class ack23 extends ACK
{
public static void main(String args[])
{
int n=ACK.ack(2,3);
System.out.println(n);
}
}}

两个文件在同一文件夹下,且classpath也设置到类文件所在文件夹,ACK文件也编译成功,
请教是为什么出现这个问题?
...全文
209 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
joejoe1991 2007-12-08
  • 打赏
  • 举报
回复
非静态方法不能直接通过类来调用
加上static就行了
awusoft 2007-12-08
  • 打赏
  • 举报
回复
public static void main(String args[])
{
int n=new ACK().ack(2,3);
System.out.println(n);
}
  • 打赏
  • 举报
回复
it really depends on what u want.

u can solve this problem by either re-declaring the ack as static method or defining a new instance of ACK class and then invoking the member method ack.

If you pick the first, then it's no sense to make class ack23 inherit from ACK at all.
cursor_wang 2007-12-08
  • 打赏
  • 举报
回复
你的这个方法int ack(int m,int n) 应该声明为静态的public static int ack(int m,int n)

62,635

社区成员

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

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