Constructor, Parameter & Argument.
Hello, Today I am going to explain what is a
Parameters & Arguments
Consider this code sample :
void car(){
}
void car (int x, String y){
}
car (2, abn345);
When considering this code sample, you can identify that,
Sea green (highlight) -- is Return Type
Red (letters)-- are the 2 datatypes
Pink (highlight)-- is the PARAMETER
Orange (letters)-- are the ARGUMENTS
When we are calling a method the values (According to the data type) that we are giving to the parameter are called ARGUMENTS.
- We can store 2 values in a parameter
- We can store number (int) and character (String) in a parameter as data.
Consider this code sample :
int car (){
}
When considering this code sample, you can identify that,
Red-- is the Return Type
Blue-- is the method name
Green-- is the parameter list
Pink-- are the open\close curly brackets
Example 1 :- int numbers (){
}
numbers (A value in integer type "5");
Example 2 :- String letters () {
}
letters (Values in String type "abc1234" );
When considering these code samples, you can identify that, the red colour letters are ARGUMENTS.
Example 3 :- int numbers (int y){
return 6;
}
//output = 6
Example 4 :- String numbers (String x){
return "ab12"
}
//output = ab12
When considering theses code samples, you can identify that, the blue colour letters are ARGUMENTS.
Construction
Consider this code sample,
class A{
public static void main(String args[]) {
System.out.println ("java")
}
}
//output = java
- This whole class is built by a constructor
This is the process that it runs
class A{
A () {
}
public static void main(String args[]) {
System.out.println ("java")
}
}
Here, the orange colour part is the constructor.
- The 1st thing that works on a programme is a constructor.
- Constructor is created by the class's name without a return type.
- The constructor is working by the object with the name of the class.
- The constructor is running only when an object is created for it.


Comments
Post a Comment