class huoException extends Exception
{
String message;
public huoException(int n)
{
message= "已装载:"+n+"t,已超重";
}
}
class chuan
{
public int zhongliang;//重量
public int xianzhong;//限重
public void xz(int x)
{
xianzhong = x;
}
public void income(int z) throws huoException
{
if( z > xianzhong )
{
throw new huoException(z);
}
zhongliang = zhongliang + z;
System.out.println("现在重量:"+zhongliang+"t");
}
public int now()
{
return zhongliang;
}
}
public class zhuanghuo
{
public static void main(String args[])
{
chuan zh = new chuan();
chuan.xz(1000);
try{
chuan.income(100);
chuan.income(500);
chuan.income(600);
chuan.income(200);
}
catch(huoException e)
{
System.out.println("出现如下问题:\n"+e.message);
}
System.out.println(chuan.now());
}
}
运行结果:
zhuanghuo.java:40: 错误: 无法从静态上下文中引用非静态 方法 xz(int)
chuan.xz(1000);
^
zhuanghuo.java:42: 错误: 无法从静态上下文中引用非静态 方法 income(int)
chuan.income(100);
^
zhuanghuo.java:43: 错误: 无法从静态上下文中引用非静态 方法 income(int)
chuan.income(500);
^
zhuanghuo.java:44: 错误: 无法从静态上下文中引用非静态 方法 income(int)
chuan.income(600);
^
zhuanghuo.java:45: 错误: 无法从静态上下文中引用非静态 方法 income(int)
chuan.income(200);
^
zhuanghuo.java:51: 错误: 无法从静态上下文中引用非静态 方法 now()
System.out.println(chuan.now());
^
6 个错误
实在不知道哪里有问题