2019.06.29问题及解析
public class Cat extends Animal{
int age = 0;
public Cat(int age) {
this.age = age;
}
public static void main(String[] args) {
Cat cat = new Cat(3);
System.out.println(cat.age);
}
}
class Animal{
int age = 2;
public Animal(int age){
this.age = age;
}
}
下列说法正确的是?
A.输出 2
B.输出3
C.输出0
D.编译错误
当父类中没有无参构造时,子类继承父类的构造方法中需要显示的调用super(parameter)父类的有参构造
Animal没有无参构造
所以Cat类并没有显示调用父类的有参构造
A.编译错误,错误
B.编译错误,错误,若父类有无参构造则选B,错误
C.编译错误,错误
D.编译错误,正确
2019.06.30问题
成员变量——正确使用
public class Test {
private int a = 1;
int b = 2;
static int c =3;
public static void main(String[] args) {
Test t = new Test();
//这里插入
}
}
下列成员变量的调用,正确的是?
A.Test.c
B.Test.b
C.this.c
D.t.a