i have a shadow of doubt about the concept of object declaration
i would illustrate my doubt with an example
superclass RefVariable = new subclass();
it will create memory space for an object of "subclass" class and would appoint a variable of type superclass named as RefVariable with the reference of the object created .....
Now my questions rare :
what this RefVariable actually contains?
what are its capability?
Is it carrying a pointer to the superclass object?
Or is it carrying some sort of address to a memory location?
I am really confused with this....please help
Deepak the first thing is that java doesnt have pointer... Now lets see your line
description of this line is :
superclass --> Name of class
RefVariable --> reference variable of class superclass
new--> this is keyword that will create a memory space for object.
subclass()--> calling subclass constructor.
Here RefVariable is denoting object of subclass. But its type is superclass. so its capability will be like this:
1. Using RefVariable you can call a method of subclass but same method must be defined in superclass also.
2. Using RefVariable you can access any instance variable of subclass.
3. Using RefVariable you can access static method of superclass. you cant use this to access static method of subclass.
4. Using RefVariable you can access static variable of superclass.
Now the funda is static method & variable are accessed based on reference While instance method & variable are access based on the object.
hope this will help