- 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
- Create a new
Student
class with a constructor that requires twoString
arguments:firstName
andlastName
. Use the arguments to initialize fields with the same names as the arguments. Display a message with the values forfirstName
andlastName
when an instance of the class is created. - Create an instance of the
Student
class and assign it to a variable. Check the messages printed in JShell. - Create an instance of the
Student
class and assign it to a variable. Check the messages printed in JShell.
Exercise 2
- Create a function that receives two
String
arguments:firstName
andlastName
. Create an instance of the previously definedStudent
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 theStudent
class later to perform the same task. However, we will learn more about this in the forthcoming chapters. - Call the previously created function with the necessary arguments. Check the message printed in JShell.
推薦閱讀
- C# 7 and .NET Core Cookbook
- 面向STEM的Scratch創新課程
- Python 3破冰人工智能:從入門到實戰
- The HTML and CSS Workshop
- C#程序設計教程(第3版)
- C專家編程
- Python 3.7從入門到精通(視頻教學版)
- MATLAB GUI純代碼編寫從入門到實戰
- 現代C:概念剖析和編程實踐
- Python Programming for Arduino
- Learning ROS for Robotics Programming
- 大話程序員:從入門到優秀全攻略
- Java EE互聯網輕量級框架整合開發:SSM+Redis+Spring微服務(上下冊)
- Mastering Android Application Development
- Microsoft Hyper-V PowerShell Automation