I'll see if I can make this a little more clear. Just because a class is declared abstract, doesn't mean that the accessible methods and fields do not exist. (Which I noticed class A doesn't even need the abstract class modifier because none of the methods are declared abstract) Just add a constructor to the A object with a System.out.println("BLAH BLAH constructor A") statement and you'll see that the compiler does indeed create an object A. Abstract classes follow the same inheritance rules as any object. You declare an abstract class because you may want a base class as a starting point for other, more meaningful objects. For example, take a class Automobile, which defines certain criteria that every automobile has but is too 'abstract' to justify creating an object. How would you initialize it's state?? What color, horsepower, type??? As a programmer, you would want anyone using this abstract object to define subclasses based on the criteria you define as abstract methods in order to require a subclass to define it's behavior more concretely.
With that said, when the x() method is invoked on the C object, through inheritance rules C also contains an x() method THAT RETURNS BY VALUE an integer encapsulated in the A object. The C object has no access to the A.x instance variable, only to the value that x is when the x() method is called. Having access to that variable would mean anyone extending the A object could modify the variable. Which you obviously cannot do.
Hope this helps.
Originally posted by Selim Hendrickson:
Hi, I think I haven't made myself clear. Now, if there were a superclass instance ( which is not possible since A is abstract ) such as:
A a = new A();
and an instance of class C had access to private variables of "a" through accessor method x() then I wouldn't have been confused.
But first of all there is no instance of A. There is only one object of class type C which extends and inherits all members of abstract A except for the private variables. Then x() method is invoked using an instance of class type c which I believe should be invoking the inherited x() method of c. But how does the inherited method x() return x when x is not inherited. x() simply executes as if it still has a connection with A. Obviously I must be missing something, so I'd be gratefull if you could point the flaw in my reasoning. I'm tired I need to
Thanks ahead...
[ September 03, 2003: Message edited by: Selim Hendrickson ]
[ September 03, 2003: Message edited by: Selim Hendrickson ]
[ September 03, 2003: Message edited by: Larry Mathys ]