Child Class Methods in OOP in PHP

A child class can have its own methods. As an example, let's add a getter and setter for the year of study to our student:

php<?php
  class Student extends User {
    private $year;
    
    public function setYear($year) {
      $this->year = $year;
    }
    public function getYear() {
      return $this->year;
    }
  }
?>

In the child class, both its own methods and the inherited ones will be available. Let's test this. Create an object of the class:

php<?php
  $student = new Student;
?>

Set its name using the inherited method, and the year of study using its own method:

php<?php
  $student->setName('john');
  $student->setYear(1);
?>

Read its name and year of study:

php<?php
  $name = $student->getName();
  $year = $student->getYear();
  
  echo $name . ' ' . $year;
?>
Задание 1

In the Employee class, create a getter and setter for the salary.

Задание 2

Check that in the Employee class both its own methods and the inherited ones work.