SuperclassX.superclassVarX has a default access and hence it will be visible to all the classes within the same package and not to anyother classes outside the package including subpackages. The statements int i; i = objY.superclassVarX; Will cause errror because superclassVarX is not visible. Mark the variabl superclassVarX public or protected and it will compile. Futher superclassVarX being a memeber variable it will be assigned a default value of 0 because its of type int even if its not assigned any explict value and hence i will have a value 0.
And yes import statement is required to import SuperclassX which is defined in packageX or if you dont want import statements refer SuperclassX in SubclassY with its full qualified name as packageX.SuperclassX. as shown below
SCJP, SCWCD, SCBCD
Joined: Dec 01, 2007
Originally posted by Siddu kuruba: Hello Rahul ,
Your statement itself has answer . Compiler complains if you are using with out initialization but you are not using the variable anywhere in the code . Am i correct ?
Thanks for reply ...siddu
Ok.. I got it ...
we are initialize it in next line using the value of superclassVarX but the variable is not accessed...