-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencapsulation.php
More file actions
42 lines (38 loc) · 829 Bytes
/
encapsulation.php
File metadata and controls
42 lines (38 loc) · 829 Bytes
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
<?php
//encapsulation using private properties
class bankAccount{
private $balance=0;
public function deposit ($amount){
$this->balance+=$amount;
}
public function withdraw ($amount){
if($amount <= $this->balance){
$this->balance-=$amount;
}
else{
echo "insufficient balance<br>";
}
}
public function checkBalance(){
echo "current balance: Rs. $this->balance<br>";
}
}
$account=new bankAccount();
$account->deposit(1000);
$account->withdraw(3000);
$account->checkBalance();
class Student{
public $name;
public $class;
public function setDetails($name,$class){
$this->name=$name;
$this->class=$class;
}
public function showDetails(){
echo "student name:$this->name, class:$this->class";
}
}
$student1= new Student();
$student1-> setDetails("Greesma","4th semester");
$student1->showDetails();
?>