How to get the base directory in the Model file in Magento 2

If you want to get the base directory in the Model file in Magento 2, follow these steps:

Use the following code in your Model/example.php file:

protected $_dir;


public function __construct(
   
    \Magento\Framework\Filesystem\DirectoryList $dir
        
) {
   
    $this->_dir = $dir;
   
}

How to get the base directory in the Model file in Magento 2expoundsofttechsolution

What is inheritance?