谁知道这个程序的运行结果 和原因 谢谢了~~~~
class testA {
public testA(){
a1();
}
public void a1() {
System.out.println("A-a1");
}
}
public class testB extends testA{
int bb=0;
public testB() {
bb=1000;
}
public void a1() {
System.out.println("bb is"+bb);
System.out.println("B-a1");
}
public static void main(String[] args) {
new testB();
}
}
class testA {
public testA(){
a1();
}
public void a1() {
System.out.println("A-a1");
}
}
public class testB extends testA{
int bb=0;
public testB() {
bb=1000;
}
public void a1() {
System.out.println("bb is"+bb);
System.out.println("B-a1");
}
public static void main(String[] args) {
new testB();
}
}
解决方案 »
- ubuntu下tomcat工作正常,但是web访问localhost却一直显示“等待localhost响应”不到不知到是怎么回事。。
- DAO、BD、MVC模式,
- ssh整合问题!!!
- 求助如何压缩数据后在网络上传输
- 使用FTPClient类上传文件后,tomcat会自动关闭,Why?
- spring+hibernate+atomikos多数据源事务无法回滚
- xml如何保存textarea提取的内容
- struts 中 关于下拉列表筐中的问题
- XML表格在任意系统WEB上的表格实现
- 如何编译测试ejb的客户端程序
- 大家来谈谈WebService
- 新建了一个linux+oracle+j2ee 群,希望大家的支持。
而testA ()中又调用了a1();
所以结果是:
bb is0
B-a1
可是testA ()中又调用了a1();为什么不调用testA中的A1?
所以结果应该是:bb is0
B-a1
不知道对不对
会对结果影响吗????
我如果把int bb=0; 改成bb=别的数
会对结果影响吗????
因为在
public testB() {
bb=1000;
}
构造函数里面没有运用父类的构造函数
若:
public testB() {
bb=1000;
super();
} 这样才有可能存在输出
B-a1
结果是一样的。bb的值改要6,但在调用构造函数前,bb是没有进入到int bb=6,bb只能使用它的默认值,而int的默认值为0,所以结果永远是一样的。