Download as pdf or txt
Download as pdf or txt
You are on page 1of 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