package zhongqiuzuoye; //自己写的方法 public class Rect { public double width; public double height; Rect(double width,double height) //带有两个参数的构造方法,用于将width和height属性初化; { this.width=width; this.height=height; } Rect() //不带参数的构造方法,将矩形初始化为宽和高都为10. { width=10
Java中的异常 Exception java.lang.Exception类是Java中所有异常的直接或间接父类.即Exception类是所有异常的根类. 比如程序: public class ExceptionTest { public static void main(String[] args) { int a = 3; int b = 0; int c = a / b; System.out.println(c); } } 编译通过,执行时结果: Exception in thread