What does it mean to call a method with an argument
Square of a number
Archived
Comments (10)
- Popular
- New
- Old
You must be signed in to leave a comment
Johnson Jose
10 May 2019, 11:31
To rephrase it: You're calling for some functionality (or method).
Now this functionality might need some parameters.
For eg. If I want you to give me a +1, I will be calling a method, say "givePlusOne" but then to whom will you givePlusOne to? You should give it to me!
How will you know this? By passing my name as parameter/argument.
givePlusOne("Johnson")
+1
Seggzzy
4 June 2019, 18:21
Thanks
0
Khairul
5 May 2019, 19:12
For example, look at the following line of code:
Here, the int a is the argument of the display() method. So when you need to call a method inside your code with argument you do this in this way:
For our example it can be:
or it also can be:
+4
Seggzzy
4 June 2019, 18:19
Thanks understood
0
Seggzzy
4 June 2019, 18:20
Thanks
0
Poornima
3 May 2019, 11:44solution
In this example you need to perform square of 5.so you need to pass value 5.
syntax to call method with an argument is:
Name of method(value you need to pass)
example:
sqr(8);
+5
Seggzzy
3 May 2019, 17:34
Thanks I will try it
0
Seggzzy
3 May 2019, 17:47
I got it but where will it appear. Is it inside main method as {system.out.println( sqr(5));}
0
Aditya Shrivastava
3 May 2019, 19:32
usually yes.
and one more thing it's always be "System" not system. good luck
+1
Seggzzy
4 June 2019, 18:20
Thanks
0