- 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.
推薦閱讀
- Dynamics 365 for Finance and Operations Development Cookbook(Fourth Edition)
- Modular Programming with Python
- Kali Linux Web Penetration Testing Cookbook
- Java:Data Science Made Easy
- Visual Basic程序設(shè)計(jì)上機(jī)實(shí)驗(yàn)教程
- Fastdata Processing with Spark
- CodeIgniter Web Application Blueprints
- Continuous Delivery and DevOps:A Quickstart Guide Second Edition
- 深入淺出 HTTPS:從原理到實(shí)戰(zhàn)
- Flutter從0基礎(chǔ)到App上線
- LabVIEW數(shù)據(jù)采集(第2版)
- Python程序設(shè)計(jì)現(xiàn)代方法
- PHP程序設(shè)計(jì)高級(jí)教程
- Puppet Essentials
- JSP程序設(shè)計(jì)與案例教程