Here you can see that the value of actual parameters are initialized with help of formal parameters in function body.In java it’s strictly prohibited to declare different variables having same name in one scope.So there’s concept of global and formal parameters.
In function body,local variable overlaps global variable.If you still confused, then you should execute below program.
CODE
import java.util.Scanner;
class temp{
int a,b,c;
temp(int a,int b,int c)
{
this.a=a;
this.b=b;
this.c=c;
}
void display()
{
System.out.println(“a= “+a+” b= “+b+” c= “+c);
}
}
class initial{
public static void main(String args[])
{
int x,y,z;
Scanner s=new Scanner(System.in);
System.out.println(“Enter three numbers”);
x=s.nextInt();
y=s.nextInt();
z=s.nextInt();
temp t=new temp(x,y,z);
t.display();
}
}
OUTPUT
LOGIC
Here we have used java-scanner file to import three numbers from user.Then with the help of this keyword we have initialized actual variable of class.After it we have called display function to check that variables are initialized or not and it works well!
Recursion
You know recursion? Recursion is defined as function calls itself.To avoid infinite loop situation we’ve to mention condition that become true at one stage of recursive function .So its necessary that every recursive function use correct conditions to avoid infinite loop.For recursive function we can say that there must be one function call statement in function body through which calls itself.It’s great way to use this feature instead of writing long block of code..
function
{
function body//
.
.
.
function call//
}
We can see that at the end of body function calls itself.I think from this syntax you get the exact idea about recursion.If however unsure then visit the next code and execute it in your system.
CODE
OUTPUT
LOGIC
I hope you coders get the exact idea concerning this keyword and formula in java.If you find problem regarding this then comment below.