Easy learning with example program codes

typescript class interface tutorial

TypeScript Class:

As we discussed in earlier tutorials that TypeScript supports object-oriented programming concepts like classes, interfaces, etc. Class is act as a blue print or template for creating objects. It provides state and behaviour for its objects. A class is used to encapsulate the data for the object.

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.


className implements interfaceName{}


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

Try it:

JS Bin on

Please follow and like us:

Copyright © 2019 CodesJava Protection Status SiteMap Reference: Java Wiki