/methods command is used to list the declared methods and their signatures.
Step 1: Open terminal and execute jshell command.
$jshell
| Welcome to JShell -- Version 10.0.2
| For an introduction type: /help intro
jshell>
Step 2: Execute following statements to define sum, sub methods.
int sum(int a, int b){
return a + b;
}
int sub(int a, int b){
return a - b;
}jshell> int sum(int a, int b){
...> return a + b;
...> }
| created method sum(int,int)
jshell>
jshell> int sub(int a, int b){
...> return a - b;
...> }
| created method sub(int,int)
jshell>
Step 3: You can use the command /methods to list the declared methods and their signatures.
jshell> /methods
| int sum(int,int)
| int sub(int,int)
Step 4: Execute below statements to call sum and sub methods.
int result = sum(10, 20)
int result = sub(10, 20)
jshell> int result = sum(10, 20)
result ==> 30
jshell> int result = sub(10, 20)
result ==> -10
No comments:
Post a Comment