constructor and supper code example
Example 1: super in javascirpt
class Rectangle {
constructor(height, width) {
this.name = 'Rectangle';
this.height = height;
this.width = width;
}
sayName() {
console.log('Hi, I am a ', this.name + '.');
}
get area() {
return this.height * this.width;
}
set area(value) {
this._area = value;
}
}
class Square extends Rectangle {
constructor(length) {
this.height;
super(length, length);
this.name = 'Square';
}
}
Example 2: how to do two constructors with super
public Person(String name){
this(name, 18, "Atlanta");
}
public Person(String name, int age){
this(name, age, "Atlanta");
}
public Person(String name, int age, String homeTown){
this.name = name;
this.age = age;
this.homeTown = homeTown;
}