Parameters,Arguments & Constructor
Parameters and Arguments
Today we're here to discuss about parameters and arguments in JAVA.
Let's look at it by studying the above example.
- Parameter is there to keep inputs and outputs.
- Information can be passed to a method by using parameter list.
- Parameters act as variables inside a method.
- We can add many Parameters by seperating with commas.
- When a parameter is passed to a method,it is called an argument.
- Arguments in JAVA are actually the values that are passed to the variables in a method.
- Return type is used to return the output.
- In JAVA, the default return type is "void".It can return any data type or String value.
- And also String or any data type can be used as the return type.But we must use the "return" keyword inside the method.
int z=x*y;
return z;
System.out.print(z);
}
area (7,13);
2) String aBC (String a,int b){
return "hello",8 ;
}
aBC ("hello",8);
Constructor
A Constructor is a method that is created by using the name of the class,called only when creating the object and that haven't a return type.
Constructor is a special method that is used in JAVA programming.
We cannot always run the constructor,it can be call when creating an object.
eg:- class Example {
Example(){
}
}
Constructor calling
- When an application is working,the constructor will run first.
- We can code the things that we want to be done at first,inside the Constructor.
- Although it haven't a return type,it can pass values and use parameters and arguments in the constructor.
Let's meet again in a new article!
Until then good bye!
Comments
Post a Comment