-
superclasses and access attribute
Hi,
I have a couple of questions:
What access attribute should static fields have? How about static final fields?
Can you store a reference to a superclass object in a subclass reference variable? Do you know of an examples?
Thanks a lot
-
What access attribute should static fields have? How about static final fields?
That depends on wether you need to be able to change the value of the variable or
if it is a fixed value. For final static values private access has no meaning, they can't
be changed anyway. Static fields can be public, protected or private and you must
use the access attribute that suits your application, i.e. what parts of your app needs
to read/write the fields.
Can you store a reference to a superclass object in a subclass reference variable? Do you know of an examples?
If ClassB is an extension of ClassA, then of course ClassB can reference instances of
ClassA. If you want ClassB to refefence its own superclass you do this by using:
super.aSuperclassMethod();
super.aValue=someValue;
the super prefix is only required if you have overridden the method/field in the
subclass.
...the question is rather strange though
Last edited by sjalle; 10-09-2005 at 07:27 AM.
eschew obfuscation
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks