This is designed to incentify community members as a proof of contribution token.

Using this You can,Buy courses,Reward others and exchange for real money.


Real Problems! Real Experts!

Join Our Telegram Channel !

The Eduladder is a community of students, teachers, and programmers. We help you to solve your academic and programming questions fast.
In eduladder you can Ask,Answer,Listen,Earn and Download Questions and Question papers.
Watch related videos of your favorite subject.
Connect with students from different parts of the world.
Apply or Post Jobs, Courses ,Internships and Volunteering opportunity. For FREE
See Our team
Wondering how we keep quality?
Got unsolved questions? Ask Questions

Buy Now
TypeScript-Interview-Questions-Intermediate-->View question

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

List some features of classes. Explain classes with example .

Asked On2019-06-18 14:28:28 by:Jaynil-Gaglani

Taged users:

Be first to like this question

Be first to dislike this question
Talk about this  Like  Dislike
View all questions

Class in term of OOPs is a blueprint for creating objects. TypeScript supports object-oriented programming features like classes, Interfaces, Polymorphism, data-binding etc. Object means this a real world entity. JavaScript ES5 or earlier didn’t support classes. Typescript inherits this feature from ES6.

In class group of objects which have common properties. Class contains fields, methods, constructors, Blocks, Nested

class and interface.

Syntax to declare a class:

class class_Name{   



Here, in place of class_Name, name will be there, and inside field and method or function.

If we compile this, It will generate JavaScript code.

// Generated by typescript 1.8.10

var Person = (function () {

   function Person() {


   return Person;


We will see a simple example:

class Person {

perCode: number;

perName: string;

constructor(code: number, name: string) {

this.perName = name;

this.perCode = code;


getGrade() : string {

return “A+” ;



The example declare a Student class which has two fields that is perCode and perName and a constructor which is special type of function which is responsible for variable or object intialization. Here is paramatrized constructor. And this keyword which refers to the current instance of the class.

getGrade() is a simple function.

The TypeScript compiler will convert the above class in JavaScript code:


An object is an instance of class which contains set of key value pairs. It’s value may be scalar values or functions or even array of other objects.

The syntax is given below ?

var object_name = {

   // scalar value

   key1: “value”,


   // functions

   key2: function() {



   // collection 

   key3:[“content1”, “content2”]


An objects can contain scalar value, functions and structures like arrays and tuples.

We can represent object in literal notation:

var person = {




// Access the object values





Let’s see with simple example:

var person = {



// Type template

Hello:function() { }


person.Hello = function() {

console.log(“hello “+person.fName)




hello Vivek

Objects as function parameters

var person = {




var hello = function(obj: { fname:string, lname:string }) {

console.log(“first name :”+obj.fname)

console.log(“last name :”+obj.lname)




first name :Vivek

last name :Ranjan

For creating Instance Objects.

To create an instance of the class, use with the new keyword followed by the class name. To allocates memory for objects with the help new during runtime. Memory allocation for all objects in heap memory area. given below:

var object_name = new class_name([ arguments ])

see with simple example declaration:

// Creating an object or instance    

let obj = new Student(); 

Accessing Attributes and Functions:

A class’s attributes and functions can be accessed by the object. With the help of ‘ . ’ dot notation we access the data members of a class.

// Accessing an attribute



// Accessing a function


We will see with the example:

class Car {

// Field


// Constructor

constructor(engine:string) {

this.engine = engine


// Function

display():void {

console.log(“Function displays Engine is :”

+ this.engine)



// Create an object

var o1 = new Car(“geeks”)

// Access the field

console.log(“Reading attribute value Engine as: ”

+ o1.engine)

// Access the function


After compilation this will convert into JavaScript code look like:

//Generated by typescript 1.8.10

var Car = (function () {

// Here is constructor

function Car(engine) {

this.engine = engine;


// Function working

Car.prototype.display = function () {

console.log(“Function displays Engine is: ”

+ this.engine);


return Car;


// Create an object

var o1 = new Car(“geks”);

// Access the field value

console.log(“Attribute value Engine as: ”

+ o1.engine);

// Access the display function



Attribute value Engine as :  geeks

Function displays Engine is : geeks


Answerd on:2019-09-12 Answerd By:Tanisha-Garg

Be first to like this answer

Be first to dislike this answer
Talk about this  Like  Dislike

You might like this video:Watch more here

Watch more videos from this user Here

Learn how to upload a video over here

Lets together make the web is a better place

We made eduladder by keeping the ideology of building a supermarket of all the educational material available under one roof. We are doing it with the help of individual contributors like you, interns and employees. So the resources you are looking for can be easily available and accessible also with the freedom of remix reuse and reshare our content under the terms of creative commons license with attribution required close.

You can also contribute to our vision of "Helping student to pass any exams" with these.
Answer a question: You can answer the questions not yet answered in eduladder.How to answer a question
Career: Work or do your internship with us.Work with us
Create a video: You can teach anything and everything each video should be less than five minutes should cover the idea less than five min.How to upload a video on eduladder