What are the difference between Classes and Interfaces in TypeScript?

devquora
devquora

Posted On: Jan 12, 2023

 

In TypeScript, a class is a blueprint for an object, while an interface is a contract for the shape of an object.

A class can have properties and methods, and can also include a constructor for initializing the object. Classes can also have access modifiers (such as "public" or "private") to control the visibility of its members.

on the other hand, an interface only defines the structure of an object, including its properties and methods, but does not provide any implementation. It can be used to define a contract that multiple classes can implement. Interfaces do not have access modifiers.

Additionally, a class can implement multiple interfaces, but can only inherit from one other class.

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    Mean Stack Interview Questions

    What is the Mean Stack?

    Mean stack is combination four popular JavaScript-based technologies MongoDB, Express, AngularJS and Node that allows d..

    Mean Stack Interview Questions

    What is Express?

    Express is lightweight web framework for Node.js.It provides robust and scalable solutions to build single and multi-pa..

    Mean Stack Interview Questions

    Explain Mongoose?

    Mongoose is a MongoDB Object Data Modeling (ODM) library for MongoDB and NodeJS.It provides a straight-forward, schema-..