Originally posted by Ayub ali khan: Could any one clear the following doubt? Can we assign a null reference to a local variable which refers to an interface? ...
Have you tried this? What happened?
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
I am using Eclipse and it prompts me to initialize the variable which refers to an interface. I have an option to click initialize. When I do that its being initialized to null. I thank Ernest for giving an instant answer to this question (before I could realize the feature of Eclipse).
Sorry for a delayed response.
Thank you for all your assistance. [ February 28, 2006: Message edited by: Ayub ali khan ]
you cannot use any kind of Object-References without initializing. Instance (aka member) variables are implicitly initialized when the object is created in the heap but the local variables are not in the stack.
Concept:
Each time an object is created in Java it goes into the area of memory known as heap (i.e instance variables also). The primitive variables like int and double are allocated in the stack, if they are local method variables and in the heap if they are member variables (i.e. fields of a class). In Java methods local variables are pushed into stack when a method is invoked and stack pointer is decremented when a method call is completed.