【发布时间】:2017-05-15 10:00:58
【问题描述】:
好的,所以多年后我正在重新访问java,当我发现我在以下sn-p中出错时,我只是在尝试一些随机程序。有人可以告诉我如何解决这个问题吗?我知道静态方法将无法访问非静态变量,但我为它创建了一个实例,对吗?另外,我对阅读其他一些问题没有任何头绪,所以请尝试帮助我。
import java.io.*;
public class phone
{
int x=6;
int getx()//I also tried using this function but everything in vain
{
return x;
}
}
public class Testing_inheritance extends phone
{
public static void main (String args[])throws IOException
{
phone xy=new phone();
int y=phone.x;
y+=10;
System.out.println("The value of x is " +y);
}
}
【问题讨论】:
-
int y=phone.x;应该是int y=xy.x;。 -
下次请附上控制台输出。
标签: java static static-methods