class InstanceVariable {
int data=50;//instance variable
public static void main(String []args) {
/* In this example if you want to access instanec variable'data' then you
have to create an instane of InstancVariable class like this*/
InstanceVariable iv = new InstanceVariable();
/* here iv is the name of the object or instance of the
InstanceVariable class */
System.out.println(iv.data);
/* to access the instance variable 'data' you have to write iv.data
}
}
50
Press any key to continue . . .
| INSTANCE VARIABLE TYPE | DEFAULT VALUE |
|---|---|
| boolean | false |
| byte | (byte)0 |
| short | (short) 0 |
| int | 0 |
| long | 0L |
| char | u0000 |
| float | 0.0f |
| double | 0.0d |
| Object | null |
First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.
Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.