Tuesday, 9 June 2020

how to create a instance with argument and will

$vikram = new BankAccount;
how to create a instance with argument and will
$vikram = new BankAccount{100);
public function __construct($df){
immediately after creation of instance
$this -> deposit($amount);
using deposit function, add the amount added in deposit function and aftet this,
echo $this -> displaybalance();
addeda amout to alred there, display the total amount
}
we can take so many arguments what we need
multiple arguments
public function __construct($df, $wa){
it is the bank account constructer
$this -> deposit($amount);
$this -> withdraw($wa);
if we creataed instances with mulitple arguments, and created consturct with arguments,, it will do the function immediately and get the result

echo $this -> displaybalance();
}
$vikram = new BankAccount{1000,500);
we cant ask greater than balance
<?php
class BankAccount {

public function __construct($df, $wa){
$this -> deposit($df);
$this -> withdraw($wa);

echo $this -> displaybalance();
}

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){
$this -> balance = $this -> balance - $amount;
}}




$vikram = new BankAccount(1000,500);

?>
instances without arguments
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){

$this -> balance = $this -> balance - $amount;

}}



$rafique = new BankAccount;

$rafique -> deposit(1000);

$rafique -> withdraw(300);

echo $rafique -> displayBalance();

echo '<br>Rafique\'s '.$rafique -> displayBalance();





$vikram = new BankAccount;

$vikram -> deposit(3000);

$vikram -> withdraw(900);

echo 'vikram\'s'. $vikram -> displayBalance();

?>


new
instance with argument
_construct
funcitons
public __constuct
->
->
new
crating an instances
how to create instancew with multiple arguments
howt o create instances with multiple arguments
will it immediately responds without writing long lines
how to write objects using multiple arguments



No comments:

Post a Comment