Re: Inheritance and lousy Frame
NickName wrote:
a) subclass object must be instantiated from the super class;
Patricia Shanahan wrote:
I don't even understand this remark.
That's because it's nonsense. It is absolutely not true. In fact, it would
almost always be a design error to instantiate a subclass object from its
superclass.
b) methods in super class need to use final keyword to prevent override
from subclass;
Patricia Shanahan wrote:
Unless they are designed and intended to be overridden. For example,
java.util.AbstractSet provides a series of default implementations of
methods in the Set interface. Most actual Set implementing classes
extend AbstractSet and override some of the methods.
There are plenty of reasons not to make a method final, if you don't use it in
a constructor. The purpose of making a method final is to prevent an override;
if you want to allow an override then you must not make the method final.
c) variable name needs to start from a lower case letter.
Patricia Shanahan wrote:
It is conventional style. The compiler does not care, but human readers
who are used to reading e.g. Sun's Java code will find it easier to read
if you do stick to the conventions.
A class name should start with an upper-case letter and otherwise use camel
case. A method or non-constant variable name should start with a lower-case
letter and otherwise use camel case. A "constant" (final variables) name
should consist of all capital letters, and is the only name type that should
contain underscores (instead of the UpperCase of a camel-case identifier).
As Patricia said, these are conventions to help humans, not a requirement of
the language. Other aspects of the conventions include indentation,
brace-placement (some controversy there), comments and more.
Patricia Shanahan wrote:
You seem to be attempting to discover the rules of the language, and how
to use it, experimentally.
Have you considered working through a book or tutorial? That would not
just explain the rules, it would explain when and how to use features.
The Sun tutorials and books like _Thinking in Java_, _Java Head Start_, _Java
in 21 Days_, and others that have been recommended will help you.
- Lew