以下是使用JShell工具时需要遵循的一些规则。
片段
jshell> class Employee { ...> private String firstName; ...> private String lastName; ...> private String designation; ...> public Employee(String firstName, String lastName, String designation) { ...> this.firstName = firstName; ...> this.lastName = lastName; ...> this.designation = designation; ...> } ...> public String getFirstName() { ...> return firstName; ...> } ...> public String getLastName() { ...> return lastName; ...> } ...> public String getDesignation() { ...> return designation; ...> } ...> public String toString() { ...> return "Name = " + firstName + ", " + lastName + " | " + ...> "designation = " + designation; ...> } ...> } | created class Employee jshell> Employee emp = new Employee("Sai", "Adithya", "Content Developer"); emp ==> Name = Sai, Adithya | designation = Content Developer