The variable is a container which store a value. Other words we can say that a variable can store some meaningful value, we do initialize when they are declared, it’s called field. A field can assign default value if they are not explicitly initialized.
Example : int velo = 3;
int speed = 40;
int km = 10;
Java have four types variable
1. Class variable; - A variable can initialize with static modifier that is called Class variable. i.e. private static String name; // It is Class variable.
2. Instance variable: - All non static fields which declare without static modifier this is called Instance variable. i.e. private int count =0; // It is instance variable
3. Local variable: - Objects store its state and field, a method store a temporary variable similar to declaring local variable in a method it said to be local variable. i.e. (int countEmp =0;)
4. Parameters :- Parameters of method is called Parameter, it signature is add(int count, float sum)
Here method of add have two parameter its type is int and float .
No comments:
Post a Comment