Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!-- ---------1--------- -->
- <?php
- class Car {
- public $name;
- function set_name($n) {
- $this->name = $n;
- }
- function get_name() {
- return $this->name;
- }
- }
- $obj = new Car();
- $obj->set_name("BMW");
- echo $obj->get_name().", ";
- $obj->set_name("TOYOTA");
- echo $obj->get_name().", ";
- $obj->set_name("Lamborgini");
- echo $obj->get_name().", ";
- ?>
- <!-- ---------2--------- -->
- <?php
- class Car {
- public $color;
- function set_color($color) {
- $this->color = $color;
- }
- function get_color() {
- return $this->color;
- }
- }
- $obj = new Car();
- $obj->set_color('Red');
- echo "Color: " . $obj->get_color();
- $obj->set_color('Green');
- echo "<br>Color: " . $obj->get_color();
- $obj->set_color('Blue');
- echo "<br>Color: " . $obj->get_color();
- ?>
- <!-- ---------3--------- -->
- <?php
- class Student {
- public $name;
- function std_name($n) {
- $this->name = $n;
- return $this->name;
- }
- }
- $obj = new Student();
- echo $obj->std_name("Yousuf");
- ?>
- <!-- ---------4--------- -->
- <?php
- class country {
- public $name;
- public $color;
- function __construct($name) {
- $this->name = $name;
- }
- function name() {
- return $this->name;
- }
- }
- $c_name = new country("Bangladesh");
- echo $c_name->name();
- ?>
- <!-- ---------5--------- -->
- <?php
- class country {
- public $name;
- public $color;
- function __construct($name="No name") {
- $this->name = $name;
- }
- function name() {
- return $this->name;
- }
- }
- $c_name = new country("Bangladesh");
- echo $c_name->name();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement