|
we can use example variables from extend, but we cant use an
example with example not reverse possible
|
|
|
<?php
|
|
|
|
|
|
class Example{
|
|
|
public $text = 'welcome to telug computer worlds';
|
|
|
public function display (){
|
|
|
echo '<h2>' .$this -> text. '</h2>';
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
class AnExample extends Example{
|
|
|
public $string = 'telugu computer world';
|
|
|
public function displayString (){
|
|
|
return '<h1>' .$this -> string .'</h1>';
|
|
|
}
|
|
|
}
|
|
|
$ae = new AnExample;
|
|
|
echo $ae -> displaystring();
|
|
|
$ex = new Example;
|
|
|
echo $ex ->displaystring();
|
|
|
|
|
|
?>
|
|
|
oop.php
|
|
|
<?php
|
|
|
class BankAccount {
|
|
|
|
|
|
|
|
|
public $balance = 0;
|
|
|
|
|
|
|
|
|
public function displayBalance(){
|
|
|
return 'Balance : '.$this-> balance. '</br>
</br>' ;
|
|
|
}
|
|
|
public function deposit($amount){
|
|
|
$this -> balance = $this -> balance + $amount;
|
|
|
}
|
|
|
public function withdraw($amount){
|
|
|
if (($this -> balance)< $amount){
|
|
|
echo 'u cant withdraw more than ur balance';
|
|
|
}
|
|
|
else{$this -> balance = $this -> balance - $amount;}
|
|
|
}}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
oop59_2.php
|
|
|
<?php
|
|
|
|
|
|
|
|
|
require 'oop.php';
|
we can use other page variables using require
|
|
class SavingsAccount extends BankAccount {
|
using extend we can use othr class
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
class CurrentAccount extends BankAccount {
|
|
|
|
|
|
}
|
|
|
|
|
|
$viki_ca = new CurrentAccount;
|
|
|
$viki_ca -> deposit(1000);
|
|
|
$viki_ca -> withdraw(30000);
|
|
|
echo '</br>current account balance '.$viki_ca ->
displayBalance();
|
|
|
|
|
|
|
|
|
$viki_sa = new SavingsAccount;
|
|
|
$viki_sa -> deposit(1000);
|
|
|
$viki_sa -> withdraw(500);
|
|
|
echo
'</br>savings account
balance '. $viki_sa -> displayBalance();
|
|
|
|
|
|
|
|
|
|
|
|
?>
|
|
| how to use other class |
| how can I declarea objects and properties and how tostore information |
| hpow to use other page variables to run the obejcts |
| how to use other cother page variables |
| how can I use |
| how to use other class variable without writing whole code |
| class |
| publuc |
| public function |
| echo |
| class extends |
| public |
| public function |
| return |
| new |
| display |
| new |
| display |
| class |
| public |
| public function |
| return |
| public funciton |
| public funciton |
| if else |
| require |
| class extends |
| class extends |
| new |
| new |
| echo |
No comments:
Post a Comment