我试过了:
int i = 5;
object o1 = i; // boxing the i into object (so it should be a reference type)
object o2 = o1; // set object reference o2 to o1 (so o1 and o2 point to same place at the heap)
o2 = 8; // put 8 to at the place at the heap where o2 points
Run Code Online (Sandbox Code Playgroud)
运行此代码后,o1中的值仍为5,但我预计为8.
我错过了什么吗?
当每个类都包含具有相同名称的方法时,在访问层次结构中的方法时遇到麻烦。
class A {
constructor(private name: string) { }
notify() { alert(this.name) }
}
class B extends A {
constructor() {
super("AAA")
}
notify() {alert("B") }
}
class C extends B {
notify() { alert("C") }
callA() {
this.notify(); // this alerts "C"
super.notify(); // this alerts "B"
// How to call notify() of the class A so it alerts "AAA"?
}
}
new C().callA();
Run Code Online (Sandbox Code Playgroud)