-
Notifications
You must be signed in to change notification settings - Fork 4
/
Encapsulation.html
67 lines (64 loc) · 1.69 KB
/
Encapsulation.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Encapsulation</title>
</head>
<body>
<!-- <script>
class employee {
setEmployeeDetails(name, id, dis) {
this.name = name;
this.id = id;
this.dis = dis;
}
getEmpName(name) {
return this.name;
}
getEmpid(id) {
return this.id;
}
getEmpdis(dis) {
return this.dis;
}
}
let emp = new employee();
emp.setEmployeeDetails("Nipun", 14, "Student");
document.write(emp.getEmpName());
document.write(emp.getEmpdis());
document.write(emp.getEmpid());
</script> -->
<script>
class student {
constructor() {
var name;
var marks;
}
getName() {
return this.name;
}
setName(name) {
this.name = name;
}
getMarks() {
return this.marks;
}
setMarks(marks) {
if (marks < 0 || marks > 100) {
alert("Invalid Marks");
} else {
this.marks = marks;
}
}
}
var std = new student;
std.setName("Nipun");
std.setMarks("10");
document.write(std.getName());
document.write("<br>");
document.write(std.getMarks());
</script>
</body>
</html>