class A extends Exception{
public A(String name){
     super(name);
}
}
class B{
int f(int a,int b) throws A{
int m;
if(0 == b){
throw new A("输入数据错误!!!");
}
else{
m = a/b;
}
return m;
}
}
class V{
public static void main(String[] args){
B bb = new B();
try{
bb.f(6,0);
}
catch(Exception e){
e.printStackTrace();
}
}
}
为什么super(name)可以直接输出形参的内容呢,看不懂api啊
class A{
public A(int b){
                   int b;
this.b = b;
System.out.printf("%d",this.b);
}
}
class AA{
public static void main(String[] args){
A aa = new A(3);
}
}
为什么这样会错啊。class A{
int b;
public A(int b){
this.b = b;
System.out.printf("%d",this.b);
}
}
class AA{
public static void main(String[] args){
A aa = new A(3);
}
}
为啥这样就对了,详细点啊,多讲讲形参怎么用啊,谢谢了

解决方案 »

  1.   

    public A(int b){
      int b;
    this.b = b;
    System.out.printf("%d",this.b);
    }两个局部变量b重名了,并没有成员变量b,哪来的this.b
      

  2.   

    super(name)会调用Exception的构造函数Exception(String s)看下他是怎么实现的不就明白了吗
      

  3.   

    public A(int b){
      int b;
    this.b = b;
    System.out.printf("%d",this.b);
    }
    第一个错 你形参的int b和方法里面的int b重名
    第二个错 方法中的this是指classA  你A类里面没有成员变量b  所以this.b会报错