Preference

Create the old school Magento 1 Rewrite, but it is not recommended.

Use the snippet in the Magento 2 module creator.

Files

etc/di.xml

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
	<preference for="Test" type="Mage2Gen\Module\Rewrite\Test"/>
</config>

Rewrite/Test.php

<?php


namespace Mage2Gen\Module\Rewrite;

class Test extends \Test
{

}