PHP OOPs In Hindi – PHP Abstract Classes In Hindi

PHP

PHP OOPs In Hindi PHP Abstract Classes In Hindi – Abstract Class Ka Istemal Php me isliye kiya jata hai, Taki Abstract Class Ko Koi Istemal na Kar Sake, Ise Ham Example Ke Sath Dekhte Hai |

For Example:- Derived Class Kar Sakta Hai Parent Class Ke Properties Ko Istemal |

Ek Bar Ek abstract Parent Class Ko Create Karne Ke Bad Ham abstract Parent Class (Base Class ) Ko Ham Derived Class (Sub Class ) Me Istemal kar Sakte Hain And abstract Parent Class Or Derived Class Ke Features To Alag-Alag Honge Hi. Lekin Ham Derived Class Se Parent Class Ke Features Ka Istemal Kar Sakte Hain, Lakin Ham Abstract Class Ka Koi Bhi Object Create Nhi Kar Sakte Hai |

Read Also:- PHP Access Modifiers

PHP Abstract Classes In Hindi

PHP Me Abstract Class Ka Main Istemal Hota Ki Koi Bhi Iska Object Create Nhi kar Sakta Hai, Lekin Ham PHP Inheritance Ka Istemal Karke Abstract Class Ka Istemal kar Sakte Hai |

Abstract Class Me Method Declare Ka Hona Jaruri Hai Wo Bhi Bina Implement Kiye |

abstract Classes Create Karne Ke Liye PHP me abstract keyword Ka Istemal kiya Jata Hai |

Example:

<?php
abstract class Car {
  public $name;
  public $color;
  
  public function __construct($name, $color) {
    $this->name = $name;
    $this->color = $color;
  }
  public function intro() {
    echo "The car is {$this->name} and the color is {$this->color}.";
  }
}


$obj = new Car("Dk", "Red")   // object error 
$obj->intro()
?>

Output:

Parse error: syntax error, unexpected '$obj' (T_VARIABLE) in C:\xampp\htdocs\index.php on line 17

Aap Upper Output Check kar Sakte Hai, Maine Aapko Pahle Bola Tha Ki abstract Class Ka Ham object Create Nhi kar Sakte Hai, Isliye Jab Hamne Obj->intro() Ko Call Kiya To Ye Error Aa Gaya Hai |

Example 2:

<?php
abstract class Car {
  public $name;
  public $color;
  
  public function __construct($name, $color) {
    $this->name = $name;
    $this->color = $color;
  }
  public function intro() {
    echo "The car is {$this->name} and the color is {$this->color}.";
  }
}

// Details is inherited from Car
class Details extends Car {
  public function message() {
    echo "Its Car ? ";
  }
}


$exp = new Details("Audi", "red");
$exp->message();
$exp->intro();
?>

Output:

Its Car ? The car is Audi and the color is red.

Leave a Reply

Your email address will not be published.