greet method is called on an instance of Child?class Parent { greet() { return "Hello from Parent"; } } class Child extends Parent { greet() { return super.greet() + " and Child"; } } const c = new Child(); console.log(c.greet());
super calls the method from the parent class.The Child class overrides greet but calls super.greet() to get the parent's greeting, then adds its own text. So the output combines both strings.
Child?class Parent { name: string; constructor(name: string) { this.name = name; console.log('Parent constructor: ' + this.name); } } class Child extends Parent { constructor(name: string) { super(name); console.log('Child constructor: ' + this.name); } } const c = new Child('Alice');
The Child constructor calls super(name) first, which runs the Parent constructor and logs the parent's message. Then the child's message is logged.
child.method() is called?class Parent { method() { return 'Parent method'; } } class Child extends Parent { method = () => { return super.method(); }; } const child = new Child(); console.log(child.method());
super binding.Using super inside an arrow function property causes a syntax error because arrow functions do not have their own super context.
class Parent { private _value = 10; get value() { return this._value; } set value(val: number) { this._value = val; } } class Child extends Parent { get value() { return super.value * 2; } set value(val: number) { super.value = val / 2; } } const c = new Child(); c.value = 40; console.log(c.value);
The Child setter divides 40 by 2 and sets 20 in the parent. The Child getter returns 20 * 2 = 40.
obj.method() is called?class Base { method() { return 'Base'; } } function Mixin1<T extends new (...args: any[]) => {}>(BaseClass: T) { return class extends BaseClass { method() { return 'Mixin1 -> ' + super.method(); } }; } function Mixin2<T extends new (...args: any[]) => {}>(BaseClass: T) { return class extends BaseClass { method() { return 'Mixin2 -> ' + super.method(); } }; } class Combined extends Mixin1(Mixin2(Base)) {} const obj = new Combined(); console.log(obj.method());
The class Combined extends Mixin1 applied to Mixin2(Base). So method in Mixin1 calls super.method() which is Mixin2's method, which calls Base's method. The output chains accordingly.
