下列语句正确与否?错误在何处?
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);
}}
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);
}}
解决方案 »
- 如何对JScrollPane里的输入进行正则表达式验证,不符合则不让输入
- 帮忙看下这个Java键入程序(The type keybord must implement the inherited abstract method )
- JAVA 图片浏览
- 偶滴个神啊,SMTP报文居然将近6000个字节
- 求教!还是类的问题,请多多指教.
- 菜菜的問題
- 我想实现客户端与服务器端互传文件,如何实现?
- Myeclipse向Oracle数据库中插入数据执行不动
- 急!!程序运行报错,找不到错在哪,请教高手。。。
- java 技术概观~期待你的参与!
- 如何在程序启动的时候不显示控制平台(在线等)
- 关于异常的一个有趣的问题
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)任何异常都捕捉。
catch(Exception e){
System.out.println(e.getMessage())
}