InterviewSolution
Saved Bookmarks
| 1. |
Difference between declaring a variable and defining a variable in Java |
|
Answer» Declaring a variable implies giving a DATA type to the variable such as int, float, char etc. An example of this is given as follows: int val;Defining a variable implies assigning a value to the declared variable. This value is stored in the variable. An example of this is given as follows: val = 5;A program that demonstrates declaring a variable and defining a variable in Java is given as follows: public class Demo { public static void main(STRING[] ARGS) { int val; //declaring a variable val = 5; //defining a variable System.out.println("val = " + val); } }The OUTPUT of the above program is as follows: val = 5 |
|