先ほど作成したテストコードを改造して、親クラスをextendsした子クラス内で親クラスと同名のメソッドを記述してオーバーライドしてみます。
書いたコードは以下のとおり
public class SuperClassTest2{
    public static void main(String[] args) {
        
        //オブジェクトのインスンタンスを生成する
        TestClassChild tcc = new TestClassChild();
       	
       	
       	tcc.PrintTextC();
       	tcc.PrintTextP();
        
    }
}
class TestClassChild extends TestClassParent
{
    TestClassChild() {
    	//引数なしコンストラクタ用
    	
    }
    void PrintTextC() {
    	System.out.print("PrintTextC !! \n");
    }
    
    void PrintTextP() {
    	System.out.print("PrintTextP オーバーライドテスト !! \n");
    }
}
class TestClassParent
{
    TestClassParent() {
    	//引数なしコンストラクタ用
    	
    }
    
    void PrintTextP() {
    	System.out.print("PrintTextP !! \n");
    }
    
    
}
子クラス(TestClassChild)内に「PrintTextP」というメソッドを書いて、親クラスのメソッドをオーバーライドしています。
これを実行すると以下のような結果になります。
PrintTextC !! PrintTextP オーバーライドテスト !!
もともと親クラスにあったメソッドが子クラス内に書いたメソッドに置き換えられて実行されている。
