Recent articles:
Popular archives:
Java: A platform for platforms
Sun's reorg may seem promising to shareholders but it's also a scramble for position. The question now is whether Sun can,
or wants to, maintain its hold on Java technology. Especially with enterprise leaders like SpringSource and RedHat investing
heavily in Java's future as a platform for platforms
Also see:
Discuss: Tim Bray on 'What Sun Should Do'
These tips and cautions will help you write better programs and save you from agonizing over why the compiler produces error messages.
final keyword. For example: final class BusinessRules { /* appropriate members */ }.
super (/* list of arguments */); call. Otherwise, the superclass layer will not properly initialize.
super (/* list of arguments */);); the compiler reports an error.
public void draw () method, the compiler reports an error if the subclass changes that method's access level to private, as in private void draw ().
Point p = new Circle (10, 20, 5); System.out.println (p.getRadius ()); causes the compiler to report an error. The getRadius() method would (logically) appear in the Circle class -- not the Point class -- and the compiler checks the p.getRadius() method call against the Point type's members to see if getRadius() is a member of Point (or a Point superclass).
Point p = new Point (10, 20); double rad = ((Circle) p).getRadius ();. Although the compiler allows that cast (because the compiler does not know if the reference in p is Point or a subclass, such as Circle), the JVM will note the actual reference type at runtime -- Point -- and generate a ClassCastException object because Point lacks a getRadius() method.
Last month, I presented you with a question and an exercise. Here are those questions and my answers in red: