请高人为我解释一下
public class Task1 {
public static void main(String[] args) {
B b = new B(5,2);
b.calc();
System.out.println(b.getP());
}
}
public class A {
protected int k = 0;
public A(int x) {
k = x;
}
public void calc(){
k = k + 1;
System.out.println("A: " + k);
}
}
public class B extends A {
protected int m;
public B(int p, int q){
super(q);
this.m = p;
}
public void calc() {
if(m % 2 == 0) {
super.calc();
}
else {
k *= 2;
System.out.println("B: " + k);
}
}
public int getP(){
return k;
}
}
侃侃尔雅