answersLogoWhite

0

In java methods what are arguments?

Updated: 8/10/2023
User Avatar

Wiki User

15y ago

Best Answer

Let's assume you have a method call, and a method, like this:

// In the main program:
int x = 5;
myMethod(x, 10)
...

// Some lines later:
void myMethod (int parameter1, int parameter2)
{
// Do something here
}

The arguments - values 5 and 10 - are passed to the method, myMethod. This means a copy of these values is passed to the method, for its use. (Technically, the values are placed on the stack, where the other method accesses them.)

The method will then have the values available. This allows for a method to be flexible, being able to processes different sets of data. For example, instead of writing a method to calculate the square root of 2, you write a method that calculates the square root of any number - passed as an argument.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

15y ago

Arguments are the values passed as parameters to the method which could be used in the method.

Example:

public int addTwoNums(int a, int b) {

return a + b;

}

here a & b are the arguments for the method addTwoNums

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: In java methods what are arguments?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Is it possible to override overloaded methods why?

Yes. Overloaded methods are also Java methods and all Java methods can be overridden.


How can you pass run-time arguments in java?

Once you have compiled your Java source files: javac MyClass.java You can run the resulting class file and pass arguments: java MyClass arg0 arg1 arg2


Explain three different methods in java?

There are three different methods /functions in java are there : 1)computational methods.2)manipulative methods.3)procedural methods.


What is function overloading in java?

Any function or method in Java that is coded by the programmer is called a user defined method in Java. The JAVA API (Application Programming Interface) has a set of predefined classes & methods that are for our usage. Whatever methods we create apart from these are termed as user defined methods. In java we not use the term functions. We call them "Methods"


What is a java object?

A java object is a collection of methods and properties defined in the Java programming language.


What are impure functions in Java?

Pure functions are those which do not modify the state of an object. Most often these are functions which take arguments and return a result.


What is an IllegalArgument Exception?

An IllegalArgument exception is usually generated when the arguments passed to a method do not match the data type of the arguments the method expects. Most of these problems are caught by the compiler but in cases where Java Reflection is used to generate and call methods dynamically, we can often encounter this exception.


The actions in a java class are called?

The actions in a java class are called methods.


What is compile time polymorphism in java?

Compile Time Polymorphism in Java is when you have the several methods with same name and different parameters and compiler has to decide how to select which method has to run based on the arguments hence the name Compile time polymorphism or method overloading.


What makes up a Java class?

Fields and methods. Fields are variables defined at the class level, i.e., they are available for all methods. Methods are the equivalent of functions / procedures, but they are defined for a specific class.


Who invoke main function in java?

The Java Runtime Environment invokes main methods.


Why the actual arguments declared as float is accepted only as double in formal arguments in java?

Sorry I don't Think I could Solve It