Question:

What is the purpose of arguments in Java?

by  |  earlier

0 LIKES UnLike

I am new to Java. What difference will it make if I declare variables inside the method instead of using arguments? Can you give a scenario that demands exclusive usage of arguments?

 Tags:

   Report

3 ANSWERS


  1. Variables defined within a function have scope (exist) only while the function is being executed. Without passing arguments, the only way external information could get into the function would be thru using global variables, which is something that should be used as little as possible for a myriad of reasons.


  2. Arguments allow you to pass information to a method. An example is:

    System.out.println("Hello, world!");

    The String "Hello, World!" is an argument being passed to the method println(), and the method then prints the argument to the console. If the method did not accept arguments and only printed "Sorry" it would not be very useful.

  3. Arguments allow you to put values into an object or a function. An object that has no member variables or a function with no variables can only be useful as an output function, like printing.

Question Stats

Latest activity: earlier.
This question has 3 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions