June 2017
Beginner
1296 pages
69h 23m
English
[Note: This section may be read after studying Chapter 3, Introduction to Classes, Objects, Methods and Strings.]
In Section 25.3, we demonstrated basic JShell capabilities. In this section, we create a class and manipulate an object of that class. We’ll use the version of class Account presented in Fig. 3.1.
Start a new JShell session (or /reset the current one), then declare class Account—we ignored the comments from Fig. 3.1:
jshell> public class Account {
…> private String name;
…>
…> public void setName(String name) {
…> this.name = name;
…> }
…>
…> public String getName() {
…> return name;
…> }
…> }
| created class Account
jshell>
JShell recognizes when you enter the ...
Read now
Unlock full access