本帖最后由 惠晖 于 2012-11-12 13:42 编辑
class NoValueException extends RuntimeException
{
NovalueException(String message)
{
super(message);
}
}
interface Shape
{
void getArea();
}
class Rec implements Shape
{
private int len,wid;
Rec(int len,int wid)
{
if (len<=0 ||wid<=0)
{
throw new NoValueException("非法直");
}
this.len=len;
this.wid=wid;
}
public void getArea()
{
System.out.println(len*wid);
}
}
class ExceptionTest
{
public static void main(String[] args)
{
Rec r =new Rec(3,-6);
r.getArea();
System.out.println("over");
}
}
这里哪里错了啊 |
|