Answer the question
In order to leave comments, you need to log in
What is wrong in this code?
I started to study OOP in php, I write the code as they say in the video lesson, but an error occurs:
Fatal error: Class Car contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Car::showInfo) in C:\OSPanel\domains\localhost\index.php on line 30
<?php
class Car {
public $name;
public $year;
public $type;
protected $hp;
protected $price;
function con ($name,$year, $type, $hp, $price) {
$this->name = $name;
$this->year = $year;
$this->type = $type;
$this->hp = $hp;
$this->price = $price;
}
public function tuning() {
$this->hp += 50;
}
public function showHp() {
echo $this->hp;
}
abstract public function showInfo();
}
class Mustang extends Car {
public function tuning() {
parent::tuning();
$this->hp += 450;
}
public function showInfo() {
echo $this->name;
}
}
$mustangGT = new Mustang();
$mustangGT->con('Mustang GT', 2017, 'Muscle car', '900' , 39000);
echo $mustangGT->showHp();
$mustangGT->tuning();
echo "<br>";
echo $mustangGT->showHp();
?>
Answer the question
In order to leave comments, you need to log in
The
Car class has an abstract method, the class must also be declared abstract
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question