aspose file tools
The moose likes Beginning Java and the fly likes default value for object refernce Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "default value for object refernce" Watch "default value for object refernce" New topic
Author

default value for object refernce

sai donthneni
Ranch Hand

Joined: Mar 26, 2006
Posts: 50
What is the default value for an object refernce. Is the null a default value for these refernce variables. What if an object is instantiated and it has no constrcutor... Is the default value null?

When you use that refernce varaible to the left of instanceof operator with the Object on the right side of the operator. Will it produce false?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16483
    
    2

The default value for a variable that can contain an object reference is null. But your question "What if an object is instantiated and it has no constrcutor" doesn't mean anything. You can only instantiate an object by calling one of its constructors, and it isn't possible for a class to not have any constructors.

And your other question is what does "null instanceof Object" return? I will leave you to write a one-line test program for that.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

All classes have a constructor. If none are explicitly written into the class definition, then a default no-args constructor is provided by the compiler.

Class/instance variables for non-primitive types are automatically initialized to null. However, local variables (e.g., declared within a method) must be explicitly initialized before they are used or a compiler error will result.

As for "null instanceof ..." See JLS 15.20.2.


"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 agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: default value for object refernce
 
Similar Threads
unboxing issues
overriding doubt
Inner class
Sequence Of events by JVM
null and not null in java