What do you understand by classes in Typescript? List some features of classes.

devquora
devquora

Posted On: Feb 22, 2018

 

We all know that Typescript is a type of object-oriented JavaScript and supports object-oriented programming features like- classes, interfaces, etc. Here, a class in terms of object-oriented programming is a blueprint for creating objects. A class is used to encapsulate data for the object. A built-in support is provided by Typescript for this feature. The “class” keyword is used to declare a class in Typescript.
Example
 

class Greeter {
    greeting: string;
    constructor (message: string) {
        this.greeting = message;
    }
    greet() {
        return "Hello, " + this.greeting;
    }
}  

Some features of a class are-

  • Encapsulation i.e. creation of self-contained modules that bind processing functions to the data, takes place.
  • Classes are created in hierarchies and with the help of inheritance; the features of one class can be used in the other.
  • Polymorphism takes place.
  • Abstraction

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    Typescript Interview Questions

    What is Typescript?

    Typescript is a free and open-source programming language which is designed and developed by Microsoft. It was designed ..

    Typescript Interview Questions

    List some features of Typescript?

    Features of Typescript are:- Typescript can be compiled to all major versions of Javascript(ES3,ES5,ES6,ES7). Typescrip..

    Typescript Interview Questions

    List some benefits of using Typescript?

    Following are some benefits of using Typescript One of the biggest advantages of Typescript is its code completion and ..