DEVFYI - Developer Resource - FYI

What is the difference between declaring a variable and defining a variable?

Java Interview Questions and Answers (part 3)


(Continued from previous question...)

493. What is the difference between declaring a variable and defining a variable?

In declaration we just mention the type of the variable and it's name. We do not initialize it. But defining means declaration + initialization.
e.g String s; is just a declaration while String s = new String ("abcd"); Or String s = "abcd"; are both definitions.

(Continued on next question...)

Other Interview Questions