Question

In Java, which is a variable that gets its value from an argument: a local variable,...

In Java, which is a variable that gets its value from an argument: a local variable, a boolean expression, a parameter, or an argument?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

A Parameter, Or Argument:

In java parameter is a variable that gets its value from argument A parameter is a value that you can pass to a method in Java. Then the method can use the parameter as though it were a local variable initialized with the value of the variable passed to it by the calling method.An argument is a value passed to a function when the function is called. Whenever any function is called during the execution of the program there are some values passed with the function. These values are called arguments. An argument when passed with a function replaces with those variables which were used during the function definition and the function is then executed with these values.

Example:

public class Example {

   public static int multiply(int a, int b)
   {
       return a + b;
   }

   public static void main(String[] args)
   {
       int x = 2;
       int y = 5;

       // the variables x and y are arguments
       int sum = multiply(x, y);

       System.out.println("SUM IS: " + sum);
   }
}

Output:

SUM IS: 7
In the above example in the function main the variable x and y are the arguments.

A parameter is a variable used to define a particular value during a function definition. Whenever we define a function we introduce our compiler with some variables that are being used in the running of that function. These variables are often termed as Parameters. The parameters and arguments mostly have the same value but theoretically, are different from each other.

public class Example {

   // the variables a and b are parameters
   public static int multiply(int a, int b)
   {
       return a + b;
   }

   public static void main(String[] args)
   {
       int x = 2;
       int y = 5;

       int sum = multiply(x, y);

       System.out.println("SUM IS: " + sum);
   }
}

Output:

SUM IS: 7
In the above example in the function multiply the variable a and b are the parameters.

ARGUMENT:

-When a function is called, the values that are passed in the call are called arguments.

-These are used in function call statement to send value from the calling function to the called function.

-These are used in function call statement to send value from the calling function to the called function.

-They are also called Actual Parameters.

PARAMETER:

-The values which are written at the time of the function prototype and the definition of the function.

-These are used in function header of the called function to receive the value from the arguments.

-Parameters are local variables which are assigned value of the arguments when the function is called.

-They are also called Formal Parameters.

Add a comment
Know the answer?
Add Answer to:
In Java, which is a variable that gets its value from an argument: a local variable,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • true or false in JAVA 1) A literal value is a value that is typed directly...

    true or false in JAVA 1) A literal value is a value that is typed directly into the code, such as 10, 14.6, or "Bob". 2) Local variables can only be accessed from within the block in which they are defined. 3) All variables must be declared before they can be used. 4) If a method returns nothing, its return type should be null. 5) A method with an int parameter can be invoked with a String argument. 6) A...

  • this is java 4. (2 point each) What value will be assigned to the "answer" variable...

    this is java 4. (2 point each) What value will be assigned to the "answer" variable below? If the expression will not compile in Java, explain why. Write your answer on the line to the right. a. boolean answer = 6 < 2 || 7 > 3; b. boolean answer = true && false; c. boolean answer = ! (87 == 80); d. boolean answer = true > false; e. String name = "Daniel" ; boolean answer = ! (name.equals("Charles"));...

  • In Java please, Create a class called airConditioner which has 3 private attributes; integer temperature, boolean...

    In Java please, Create a class called airConditioner which has 3 private attributes; integer temperature, boolean on and String location and has 5 behaviors: turning the air conditioner on and off (called turnON and turnOFF with no return and no arguments) checking to see if the air conditioner is on (called isON wihch returns boolean) sets the temperature( setTemp which receives an int argument) and gets current temp (getTemp) which accepts no value and returns the int temp

  • 1. In a function that gets a value from the keyboard and communicates that value to...

    1. In a function that gets a value from the keyboard and communicates that value to the main function via a parameter, the parameter used is considered __________. 2. In a function that receives a value from the main function via a parameter and then displays the parameter value on the screen, that parameter is considered __________. 3. In a function that receives one parameter value from the main program and passes back a changed value of the parameter, that...

  • Write a Java code to define an interface called FrugalList which contains a method named pushBack....

    Write a Java code to define an interface called FrugalList which contains a method named pushBack. The method pushBack takes an Object type argument and returns a boolean value.

  • Write a class in java for objects that store information about fish. For each fish you...

    Write a class in java for objects that store information about fish. For each fish you need to store its breed (a string) and whether or not it is edible (a boolean). Provide a default conStructor, and an initial value constructor that accepts the breed as its parameter. The initial value conStructor must call the default constructor. By default a fish is not edible. Provide JUSt one mutator method that receives a string parameter, and sets the edible variable to...

  • Code in JAVA You are asked to implement “Connect 4” which is a two player game....

    Code in JAVA You are asked to implement “Connect 4” which is a two player game. The game will be demonstrated in class. The game is played on a 6x7 grid, and is similar to tic-tac-toe, except that instead of getting three in a row, you must get four in a row. To take your turn, you choose a column, and slide a checker of your color into the column that you choose. The checker drops into the slot, falling...

  • java programming. One. Write a method public boolean hasOnlyoddDigits(int n) that returns true if its parameter...

    java programming. One. Write a method public boolean hasOnlyoddDigits(int n) that returns true if its parameter n contains only odd digits (1, 3, 5, 7, or 9), and returns false otherwise. Zero is counted as an even digit whenever it appears inside the number. Remember that for a positive integer n, the expression (n % 10) gives its last digit, and the expression (n / 10) gives its other digits. Correct answer true false false false 357199 7540573 97531000

  • Synchronization, race condition, etc. Which of the choices are correct? Consider the code below in Java,...

    Synchronization, race condition, etc. Which of the choices are correct? Consider the code below in Java, corresponding to the implementation of a list using an array: public class MyArrayList private int[] array- new int [MAX_SIZE]; private AtomicInteger size-new AtomicInteger() public void insert(int element) do int position - size.get); array[position] - element; 3 while (!size.compareAndSet(position, position + 1)); Assume that the list is initially empty, and that two threads call insert simultaneously, one with parameter 5, and one with parameter 9....

  • Java!!! Write a program that takes a file name as its command line argument. It assumes...

    Java!!! Write a program that takes a file name as its command line argument. It assumes the file is a binary data file and checks the first 4 bytes of the file to see whether they contain the integer −889275714. It outputs “yes” or “no” or an error message if there was an IOException generated. (Trivia question: Why test for that particular value? Hint: Try it on several .class files.)

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT