Site Search:

Class Design

with hidden methods, the specific method used depends on where it is referenced. If it is referenced within the super class, the method declared on super class is used.

abstract method cannot contain a body.

A concrete class must implement all inherited abstract methods.

an interface can extend multiple interfaces.

interface variables are assumed to be public static final.

an abstract class may contain concrete methods.

Since java 8, interfaces may also contain concrete methods in form of static or default methods.

interface does not inherit java.lang.Object, otherwise, java would support multiple inheritance for objects, which it doesn't.

A reference to an object requires an explicit cast if referenced with a subclass. If the cast is to a superclass reference, then an explicit cast is not required.

Because of polymorphic parameters, if a method takes the superclass of an object as a parameter, then any subclass references may be used without a cast.

Some cast exceptions can be detected as errors at compile-time, but others can only be detected at runtime.

Due to polymorphism, a public instance method can be overridden in a subclass and calls to it will be replaced even in the super class it was defined.

protected and public methods may be overridden, not hidden. private methods are always hidden in a subclass. static methods cannot be overridden, only hidden. variables may only be hidden.

when overriding a method, a subclass can define a method with an exception that is a subclass of the exception in the parent method; the return types have to be covariant; subclass must define a method that is more accessible than the method in the parent class; for nonprivate methods in the parent class, both methods must use static (hide) or neither should use static (override).