Data types and Variables
Datatype:
Specifies the size and then type of values that can be stored in an identifier.
They are used to represent how much memory is required to hold the data.
Variables:
Variables are nothing but a name given to storage area.
Three types of variables:
1. Local Variable
2. Instance variable
3. Static variable
1. Local Variable: A local variable in Java is a variable that’s declared within the body of a method. Then you can use the variable only within that method. Other methods in the class aren’t even aware that the variable exists. If we are declaring a local variable then we should initialize it within the block before using it.
The variables which are declared inside a class outside any method /block/ a constructor are known as instance variables.
Comments
Post a Comment