- 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.
推薦閱讀
- MySQL 8從入門到精通(視頻教學版)
- Data Analysis with IBM SPSS Statistics
- Python機器學習算法與實戰
- bbPress Complete
- Access 2010數據庫應用技術(第2版)
- Java網絡編程核心技術詳解(視頻微課版)
- 深入剖析Java虛擬機:源碼剖析與實例詳解(基礎卷)
- Bootstrap for Rails
- C++從入門到精通(第6版)
- 從程序員角度學習數據庫技術(藍橋杯軟件大賽培訓教材-Java方向)
- Java程序設計教程
- Java編程指南:語法基礎、面向對象、函數式編程與項目實戰
- Java EE輕量級解決方案:S2SH
- Visual FoxPro數據庫程序設計
- Qt編程快速入門