CodesJava

Easy learning with example program codes

typescript class interface tutorial

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.
Use implements keyword to implement interfaces.

Syntax:

className implements interfaceName{}

Example:

interface IPerson { 
   name:string; 
} 
 
class Employee implements IPerson {  
   empId:string;
 
   constructor(name:string,empId:string) { 
      this.name = name; 
      this.empId = empId; 
   } 
} 
 
var obj = new Employee("Jai","EMP024");
console.log("Name: "+obj.name);
console.log("Emp Id: "+obj.empId);


Please follow and like us:
error








Copyright © 2019 CodesJava DMCA.com Protection Status