Quiz : https://take.quiz-maker.com/QZHMSPRBI
Java Variables
- Variables are the container which hold the value, value can me change depend on condition.
- A variable assigned with a data type.
- Variable is a name of memory location.
- Types:
- Local
- static
- instance
- Local variable:
- A variable declared inside the body of the method is called local variable.
- Access modifiers cannot be used for local variables.
- A local variable cannot be defined with "static" keyword.
- Instance variable:
- A variable declared inside the class but outside the body of the method.
- A Instance variable cannot be defined with "static" keyword.
- Static variable:
- A variable that is declared as static is called a static variable.
- Static variable can be use for a entire program.
- It cannot be local.
- Memory will be allocated to the static variable at the time of class loading.
- Example:
Public class Abhinav{
static int Ram=100;//static variable
void manvik(){
// method body
int n=90;//local variable
}
public static void main(String args[]){
int age = 21;//instance variable
}
}
Comments
Post a Comment