Skip to content

Commit 7883718

Browse files
updated
1 parent e9c5b8a commit 7883718

2 files changed

Lines changed: 60 additions & 1 deletion

File tree

25_Revision/19_oops_and_classes/08_inheritance.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,40 @@ class User {
77
}
88
loginMessage(){
99
console.log(`Hi ${this.username} you are logedin`)
10+
return (`Hi ${this.username} you are logedin`)
1011
}
1112
}
1213

1314
class student extends User {
14-
constructor(){
15+
constructor(username, stuClass, subject, roll){
16+
super(username)
17+
this.stuClass = stuClass;
18+
this.subject = subject;
19+
this.roll = roll;
20+
}
21+
showStudentDetails(){
22+
console.log(`student : ${this.username}, ${this.stuClass}, ${this.subject}, ${this.roll}`)
23+
return (`student : ${this.username}, ${this.stuClass}, ${this.subject}, ${this.roll}`)
24+
}
25+
}
1526

27+
class instructor extends User {
28+
constructor(username, coursesQty, sellCourse, learner){
29+
super(username)
30+
this.coursesQty = coursesQty;
31+
this.sellCourse = sellCourse;
32+
this.learner = learner;
33+
}
34+
showTeacherDetails(){
35+
console.log(`teacher : ${this.username}, ${this.coursesQty}, ${this.sellCourse}, ${this.learner}`);
1636
}
1737
}
1838

39+
40+
const student1 = new student ("Sujit", "sujit@gmail.com", "Computer Science", 80)
41+
const instructor1 = new instructor ("SujitTomar", 15, 235, 80000)
42+
43+
student1.loginMessage();
44+
student1.showStudentDetails()
45+
46+
instructor1.showTeacherDetails()
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
class User {
2+
constructor(username){
3+
this.username = username
4+
this.id = null
5+
}
6+
7+
logMe (){
8+
return(`userame ${this.username}`);
9+
10+
}
11+
// static means its function not for everyone
12+
static createID(){
13+
let id = `123`
14+
return id
15+
}
16+
}
17+
18+
let user1 = new User("iamsujittomar");
19+
console.log(user1.logMe());
20+
21+
// console.log(user1.createID())
22+
23+
class Teacher extends User{
24+
constructor(username, email){
25+
super(username)
26+
this.email = email
27+
}
28+
}
29+
30+
let teacher1 = new Teacher ("sujittomar", "sks@gmail.com")
31+
console.log(teacher1.logMe());

0 commit comments

Comments
 (0)