Java高手帮忙,谢谢~

[复制链接]
查看11 | 回复4 | 2008-8-15 03:48:43 | 显示全部楼层 |阅读模式
class testexp
{
public static void main(String[] args)
{
try
{
//int result =new test().devide(3,0);

int result =new test().devide(3,-2);
//int result =new test().devide(3,1);

System.out.println("The result is " + result);
}
catch (DevideByMinusException e)
{
System.out.println("program is running into"+ "DevideByMinusException");
System.out.println(e.getMessage());
System.out.println("the devisor isfushu");
}
catch (ArithmeticException e)
{
System.out.println("program is running into"+ "ArithmeticException");
System.out.println(e.getMessage());
}
catch (Exception ex)
{
System.out.println("program is running into"+ "other unknowned Exception");
System.out.println(ex.getMessage());
}

System.out.println("正常执行结束");
}
}
class test
{
public int devide(int x,int y)throws ArithmeticException,DevideByMinusException
{
if (y<0)
throw new DevideByMinusException("除数为负值:"+ y);

return x/y;
}
}
class DevideByMinusException extends Exception
{
public DevideByMinusException (String st)
{
super(st);
}
}
==========================
最后面函数中的super(st);在这个程序中有什么作用?
如果缺少,会有什么后果?
恳请各位高手指点迷津,不胜感激····
==========================

回复

使用道具 举报

千问 | 2008-8-15 03:48:43 | 显示全部楼层
缺少也没关系..它的作用就是call parent class的constructor...
回复

使用道具 举报

千问 | 2008-8-15 03:48:43 | 显示全部楼层
调用父类的构造方法,
回复

使用道具 举报

千问 | 2008-8-15 03:48:43 | 显示全部楼层
Java中的super关键字的知识点总结:1.子类的构造函数如果要引用super的话,必须把super放在函数的首位class A {
A(){
System.out.println("A");
}
}
public class B extends A{ B(){
回复

使用道具 举报

千问 | 2008-8-15 03:48:43 | 显示全部楼层
调用父类的构造里面属性
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行