假设我有一个实现Runnable接口的抽象Base类.
public abstract class Base implements Runnable {
protected int param;
public Base(final int param) {
System.out.println("Base constructor");
this.param = param;
// I'm using this param here
new Thread(this).start();
System.out.println("Derivative thread created with param " + param);
}
@Override
abstract public void run();
}
Run Code Online (Sandbox Code Playgroud)
这是一些衍生类.
public class Derivative extends Base {
public Derivative(final int param) {
super(param);
}
@Override
public void run() {
System.out.println("Derivative is running with param " + param);
}
public static void main(String[] args) {
Derivative thread …
Run Code Online (Sandbox Code Playgroud) 我正在尝试覆盖类中的值。我有以下代码:
open class Balloon() {
open var textSize: Float = 20f
init {
Log.i("textSize", textSize.toString())
}
}
class BigBalloon(): Balloon() {
override var textSize = 30f
}
Run Code Online (Sandbox Code Playgroud)
但是,日志会打印出这些值:
第一个日志来自Balloon()
,第二个来自BigBalloon()
。0.0
当我将其覆盖为 时,它如何打印30
?我是否错误地实施了所有这些?
abstract ×1
android ×1
class ×1
constructor ×1
inheritance ×1
java ×1
kotlin ×1
methods ×1
virtual ×1