下列语句正确与否?错误在何处?
public class test extends T1,T2
{
 public int x=0;
 public test(int x)
{
this.x=x;
}}public class test extends T1
{
 public int x=0;
 public test(int x)
{
this.x=x;
}}protected class test extends T2
{
 public int x=0;
 public test(int x)
{
this.x=x;
}
}下列输出结果
package test;
public class fatherclass
{
public fatherclass()
{
System.out.println("111");
}
}package test;
import test.fatherclass;
public class childclass extends fatherclass
{
public childclass()
{
System.out.println("222");
} public static void main(String[] args)
{
fatherclass fc=new fatherclass();
childclass cc=new childclass();
}
}下列语句会发生编译错误,加上异常处理语句,使之能够编译通过
public class test
{
public static void main(String[] args)
{
char a=(char)System.in.read();
System.out.print("输入字符为"+a);
}}

解决方案 »

  1.   

    1.
    public class test extends T1{...}
    如果T1中没有带参数的构造函数,那么可以执行通过,如果T1的构造函数有参数,则:public class test extends T1
    {
     public int x=0;
     public test(int x)
    {
         //传递给基类构造函数时,采用super关键字,而且必须是第一条语句。
                   super(x); 
                  this.x=x;
    }}2.
    运行结果:
    111
    111
    222
    3.import java.io.IOException;public class test
    {
    public static void main(String[] args)
    {
    try{
    char a=(char)System.in.read();
    System.out.print("输入字符为"+a);
    }
    catch(IOException e){
    System.out.print("error");
    }
    }}还可以用catch(Exception e)任何异常都捕捉。
      

  2.   

    hillspring(高山流水)  和我想的一样
    catch(Exception e){
      System.out.println(e.getMessage())
    }