Home arrow static arrow Java Programming [Archive] - initializing class variables
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - initializing class variables
This topic has 2 replies on 1 page.

Posts:241
Registered: 12/28/99
initializing class variables  
Jul 12, 2004 9:04 AM



 
This is kind of a basic question, so I'm a bit embarrased to be asking it - but If I have two classes where one is derived from the other (with this exact code):

public class A {  private String name=""public A(){  }} public class B extends A {   public B(){  }} 


Is there any set of circumstances where you could call B's constructor and get back an object where A.String is null?

I thought not, since new B() implicitly calls super(), and A.name is explicitly assigned a value. However, I am seeing something in my code (different from the above code) that suggests otherwise, and just wanted to confirm that my original thoughts were correct.

Thanks in advance for your help.
 

Posts:24,036
Registered: 2/3/03
Re: initializing class variables  
Jul 12, 2004 9:12 AM (reply 1 of 2)



 
Is there any set of circumstances where you could call
B's constructor and get back an object where A.String
is null?

You mean A.name == null? No - name will be initialized when a A's constructor is called.
 

Posts:241
Registered: 12/28/99
Re: initializing class variables  
Jul 12, 2004 10:42 AM (reply 2 of 2)



 
Yes, I meant A.name.

Thanks for confirming what i thought.

I have since found out that the behavior I saw was from other code that was explicitly setting a.name to null.
 
This topic has 2 replies on 1 page.