function test( a, b, c ) { // a, b, and c are the parameters
// code
};
test( 1, 2, 3 ); // 1, 2, and 3 are the arguments
int main () {
int x = 5;
int y = 4;
sum(x, y); // **x and y are arguments**
}
int sum(int one, int two) { // **one and two are parameters**
return one + two;
}
parameters: Function Definition
argument : Value passed to function
function createMenu({ title, body, buttonText, cancellable }) {
// ...
}
createMenu({
title: "Foo",
body: "Bar",
buttonText: "Baz",
cancellable: true
});
Parameter is the variable in the declaration of the function.
Argument is the actual value of this variable that gets passed to the function.
// Define a method with two parameters
int Sum(int num1, int num2)
{
return num1 + num2;
}
// Call the method using two arguments
var ret = Sum(2, 3);
function myFunction(paramOne, paramTwo){
//paramOne and paramTwo above are parameters
//do something here
return paramOne + paramTwo
}
myFunction(1,2) // 1 & 2 are arguments
function addTwoNumbers(num1, num2) { // "num1" and "num2" are parameters
return num1 + num2;
}
const a = 7;
addTwoNumbers(4, a) // "4" and "a" are arguments
variables: any declaration
val someVariable: String = "some variable"
parameters: variables within method/class declaration
fun someMethod (someParameter: String) {...}
class SomeClass (someParameter: String){...}
arguments: variables passed into a method/class call
var somevariable = someMethod(someArgument)
val someClass = SomeClass(someArgument)
property: variable declared within a class
class SomeClass(val someParameter: String){
//use parameter in class as property
...
}
/*
Note
Source:
https://developer.android.com/codelabs/
basic-android-kotlin-compose-classes-and-objects?
continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-compose-unit-2-pathway-1%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-compose-classes-and-objects#6
"If constructor doesn't specify whether the properties are
mutable or immutable, it means that the parameters are
merely constructor parameters instead of class properties.
You won't be able to use them in the class, but simply
pass them to the superclass constructor."
*/
class SubClass(deviceName: String, deviceCategory: String) :
SuperClass(name = deviceName, category = deviceCategory) {
}