TypeScript Hindi Tutorial #25 Access Modifiers

Access Modifiers

What is Access Modifiers.

Public.

Private.

Protected.

Interview Questions


product.ts

"use strict";
class Product {
name;
price;
pId;
inCart = false;
isOrdered = false;
constructor(name, price, pid) {
this.name = name;
this.price = price;
this.pId = pid;
}
addToCart() {
this.inCart = true;
}
buyProduct() {
if (this.inCart) {
return `product ${this.name} is ordered in ${this.price}`;
}
else {
return `no product in cart`;
}
}
}
class Order extends Product {
constructor() {
super('laptop', 100000, 403);
}
getPrice() {
return this.price;
}
}
var product = new Product('Samsung', 100000, 101);
// product.addToCart();
// console.log(product.buyProduct())
// console.log(product.name);
// console.log(product.price);
var order = new Order();
console.log(order.getPrice());

product.js

"use strict";
class Product {
name;
price;
pId;
inCart = false;
isOrdered = false;
constructor(name, price, pid) {
this.name = name;
this.price = price;
this.pId = pid;
}
addToCart() {
this.inCart = true;
}
buyProduct() {
if (this.inCart) {
return `product ${this.name} is ordered in ${this.price}`;
}
else {
return `no product in cart`;
}
}
}
class Order extends Product {
constructor() {
super('laptop', 100000, 403);
}
getPrice() {
return this.price;
}
}
var product = new Product('Samsung', 100000, 101);
// product.addToCart();
// console.log(product.buyProduct())
// console.log(product.name);
// console.log(product.price);
var order = new Order();
console.log(order.getPrice());