実験課題2
Exercise 2(課題2) See the section 5.1.1. "About Polymorphism". Explain the polymorphism on the program of below figures. Further, show the execution result of below figures by importing external projects chapter4kadai9 and chapter5kadai1, and its source code. Follow instruction below to show the result.
- create the Java application project named
chapter5kadai2. - import external projects named
chapter4kadai9andchapter5kadai1to this project by using the way of 2.1.2.節の方法. - create the main method to run this program as below figures.
- take a screenshot of the execution result.
public static void helloUser(User u) {
System.out.println("Hello " + u.getUserName() + '!');
}
public static void main(String[] args)
{
Student s = new Student(1, 2030, "Tanaka", "Taro");
Teacher t = new Teacher("Prof.", "Tsuyama", "Taro");
helloUser(s);
helloUser(t);
}
(5.1.1.節をよく読み、プロジェクトchapter5kadai2を作成し、プロジェクトchapter4kadai9とchapter5kadai1を参照しなさい。その後、上図のプログラムを作成し、実行後スクリーンショットを報告しなさい。また、プログラム中で多態性が機能している箇所を説明しなさい。)