// クラス継承の確認をするために、入力した文字列の長さを出力するプログラム import java.io.*; import java.lang.*; public class LengthCalculationProcess { public static void main(String[] args) { // StringModification を継承した LengthCalculation クラスのオブジェクトを作成 LengthCalculation str = new LengthCalculation(); try { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("クラス継承の確認をするために、入力した文字列の長さを出力します。"); System.out.println("文字列を1つ入力してください。"); System.out.print("文字列> "); String input = br.readLine(); // 文字列を 1 つ入力 // 入力された文字列 input を LengthCalcuation クラスのオブジェクトのフィールド変数に設定 // text は、LengthCalculation クラスが StringModification から継承したフィールド str.text = input; // 文字列の長さを調査 // length メソッドは、LengthCalcuation クラスが StringModification クラスから継承したもの int len = str.length(); System.out.println("入力された文字列の長さは" + len + "文字です。"); System.out.println("文字列の長さは、継承されたメソッドを使って求められています。"); } catch(IOException e) { } } }