local variable in java with example
Local Variable
Declaration : Local variables are declared inside the body of the methods, constructor or blocks.
EXAMPLE:
void add(){
int sum, c=10,d=20; //sum, c and d are local variables
sum=c+d;
cout<<sum;
}
Scope:
Local variable can be used inside methods , constructors or blocks but not outside. we cannot use local variable outside the methods , constructor or blocks.
When variable gets memory allocated :
Local variable gets allocated when methods , constructor or blocks get executed.
Stored memory :
Local variables are stored in stack memory.
Default values:
Local variable does not have any default values. Value should be provided before use.
Access specifier :
Access specifiers that is public , protected ,private cannot be used with local variables.
Tags:
PROGRAMMING
❤️❤️❤️
ReplyDeleteNice
ReplyDelete