50% found this document useful (12 votes)
39K views

55106-Typescript Javascript's Superset Solution

The document contains code examples for 4 Typescript questions: 1. An arrLength function that takes an array as a parameter and returns its length. 2. A Human class that is extended by an Employee class, with the Employee class inheriting properties like name and age from the Human class and adding its own like department. 3. An Automobile class that is extended by a Car class, with the Car class overriding the doPrint method to print the fuel type and price in addition to calling the super method. 4. A Restaurant class that takes a menu array in its constructor and has a list method to print out the menu.

Uploaded by

Solution Guru
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
50% found this document useful (12 votes)
39K views

55106-Typescript Javascript's Superset Solution

The document contains code examples for 4 Typescript questions: 1. An arrLength function that takes an array as a parameter and returns its length. 2. A Human class that is extended by an Employee class, with the Employee class inheriting properties like name and age from the Human class and adding its own like department. 3. An Automobile class that is extended by a Car class, with the Car class overriding the doPrint method to print the fuel type and price in addition to calling the super method. 4. A Restaurant class that takes a menu array in its constructor and has a list method to print out the menu.

Uploaded by

Solution Guru
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Course Id : 55106

Typescript – JavaScript’s Superset Solution


Note : Copy paste this code into your console

Q1: Finding Array Length

function
arrLength(inputArray:any[]) {
var length = inputArray.length;
return length;
}

Q2: Human Inheritance

class Human {
protected name: string;
protected age: number;
constructor(name: string, age : number) {
this.name= name;
this.age = age;
}
}
class Employee extends Human {
protected department: string;
protected batch:string;
protected role:string;
constructor(name:string, age: number, department: string,
batch:string, role:string) {
super(name,age);
this.department = department;
this.batch=batch;
this.role=role;
}

getInfo(){

console.log("Name: "+ this.name);


console.log("Age: "+ this.age);
console.log("Department: "+ this.department);
console.log("Batch: "+ this.batch);
console.log("Role: "+ this.role);
}
}
Q3: Automobile Polymorphism

class Automobile {
protected fuelType: string;
protected price: number;
constructor(fuelType:string, price: number) {
this.fuelType= fuelType;
this.price= price;
}
doPrint():void {
console.log("I am automobile")
}
}

class Car extends Automobie {


constructor (fuelType:string, price: number) {
super(fuelType,price);
}
printInfo() {
super.doPrint();
console.log("Fuel Type: "+this.fuelType);
console.log("Price: "+this.price);
}
}
Q4: Restaurant Class

class Restaurant {
menu: any[];
constructor(menu: any[]) {
this.menu = menu;
}

list() {
console.log(this.menu);
}
}

You might also like