created on | January 28, 2022 |
Inside methods, classes and interfaces, statements have to end with a semicolon.
defining methods
Methods can be defined inside a class as well as just “as is”, that is, without an enclosing class.
jshell> public String chat(String name) {
...> return "hi " + name + ", wassup?";
...> }
| created method chat(String)
jshell> chat("Bob")
$2 ==> "hi Bob, wassup?"
jshell>
defining classes and interfaces
Classes and interfaces are defined as usual.
listing defined classes and interfaces
Classes and interfaces that have been defined during the current session can listed with
jshell> interface ActionHero {
...> // kinda marker interface
...> }
| created interface ActionHero
jshell> /type
| class Fruit
| interface ActionHero
jshell>