官术网_书友最值得收藏!

  • Java 9 with JShell
  • Gastón C. Hillar
  • 211字
  • 2021-07-09 18:46:50

Exercises

Now that you understand an object's life cycle, it is time to spend some time in JShell creating new classes and instances.

Exercise 1

  1. Create a new Student class with a constructor that requires two String arguments: firstName and lastName. Use the arguments to initialize fields with the same names as the arguments. Display a message with the values for firstName and lastName when an instance of the class is created.
  2. Create an instance of the Student class and assign it to a variable. Check the messages printed in JShell.
  3. Create an instance of the Student class and assign it to a variable. Check the messages printed in JShell.

Exercise 2

  1. Create a function that receives two String arguments: firstName and lastName. Create an instance of the previously defined Student class with the received arguments as parameters for the creation of the instance. Use the instance properties to print a message with the first name followed by a space and the last name. You will be able to create a method and add it to the Student class later to perform the same task. However, we will learn more about this in the forthcoming chapters.
  2. Call the previously created function with the necessary arguments. Check the message printed in JShell.
主站蜘蛛池模板: 泾川县| 隆昌县| 城口县| 肥东县| 隆回县| 广元市| 沙湾县| 临桂县| 海宁市| 正蓝旗| 赤城县| 岚皋县| 从化市| 巴彦淖尔市| 张家港市| 凉山| 正宁县| 当涂县| 晴隆县| 闽清县| 贡觉县| 沅陵县| 班玛县| 云霄县| 迭部县| 桐乡市| 珲春市| 巴林右旗| 玛纳斯县| 襄汾县| 锡林浩特市| 南昌县| 额尔古纳市| 南城县| 施秉县| 大方县| 隆德县| 广南县| 正蓝旗| 大厂| 云梦县|