-
Notifications
You must be signed in to change notification settings - Fork 0
/
OPPS.js
70 lines (65 loc) · 1.77 KB
/
OPPS.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Object-Oriented-Programming
// Class & Encapsulation
class Person {
constructor(name, age){
this.name = name,
this.age = age
}
displayInfo = () => {
console.log(`Name : ${this.name}`)
}
}
const personObj = new Person("Krishna", 22)
// personObj.displayInfo()
//Inheritance
// class Student extends Person{
// constructor(name, age, rollNumber, grade){
// super(name, age)
// this.rollNumber = rollNumber,
// this.marks = grade
// }
// }
// console.log(studentObj);
//Polymorphism using method Overriding
class Student extends Person{
constructor(name, age, rollNumber, grade){
super(name, age)
this.rollNumber = rollNumber,
this.grade = grade
}
//same method that used in parent calss is overraided here
displayInfo = () => {
console.log(`Student Name: ${this.name} // Grade: ${this.grade}`)
}
}
const studentObj = new Student("Manikanta", 24, 86, 8.5)
studentObj.displayInfo()
//Abstraction
class PersonBankAcc{
constructor(name="Krishna", pincode="54542", balance = 0){
this.name = name,
this._pincode = pincode
this._balance = balance
}
deposite = (ammount) => {
this._balance += ammount
console.log(`Balance: ${this._balance} r/s`)
}
credit = (ammount) => {
if (this._balance < ammount){
console.log("Insufficient balance !")
}
else{
this._balance -= ammount
console.log(`Remaining Balance: ${this._balance} r/s`)
}
}
displayBalance = () => {
console.log(`Balance: ${this._balance} r/s`)
}
}
const myAccount = new PersonBankAcc()
myAccount.deposite(1000)
// myAccount.credit(100)
// myAccount.credit(900)
myAccount.displayBalance()