CodesJava

Easy learning with example program codes

typescript interface multiple inheritance


TypeScript interface:

An interface is declared with interface keyword. It is a way of implementing 100% abstraction. It only contains the declaration of the members. Interface forms a contract with your class that force your class to have all methods defined by the interface must appear in the class.

TypeScript provides the facility of inheritance between interfaces i.e. an interface can inherit other interface. We have to use extends keyword to implement inheritance among interfaces.

TypeScript also provides the facility to inherit multiple interfaces.

Syntax:

ChildInterfaceName extends SuperInterfaceName1, SuperInterfaceName2,…,SuperInterfaceNamen

Example:

interface IPerson { 
   age:number;
   name:string;
} 
 
interface IEmployee { 
   empId:string; 
} 
 
interface Engineer extends IPerson, IEmployee {}
 
var obj:Engineer = {name:"Asmita", age:32, empId:"EMP023"}; 
console.log("Name:  "+obj.name);
console.log("Age:  "+obj.age);
console.log("Emp Id:  "+obj.empId);

Try it:

JS Bin on jsbin.com

Please follow and like us:


Copyright © 2019 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki