Slide : java_oo.ppt
ข้อมูลจาก : http://www.sun.com/training/catalog/courses/CX-310-035.xml
Section 6: Overloading, Overriding, Runtime Type and Object Orientation
State the benefits of encapsulation in object oriented design and write code that implements tightly encapsulated classes and the relationships "is a" and "has a".
Write code to invoke overridden or overloaded methods and parental or overloaded constructors; and describe the effect of invoking these methods.
Write code to construct instances of any concrete class including normal top level classes and nested classes.
Rule
http://www.janeg.ca/scjp/overload/overloadingMethods.html
http://www.janeg.ca/scjp/overload/poly.html
- overloaded methods can have the same name but must have different parameter lists
- parameter lists are considered different if the order of the arguments are different
- a subclass method can overload a superclass method
- overloaded methods:
- appear in the same class or a subclass
- have the same name but,
- have different parameter lists, and,
- can have different return types
- overriding methods:
- appear in subclasses
- have the same name as a superclass method
- have the same parameter list as a superclass method
- have the same return type as as a superclass method
- the access modifier for the overriding method may not be more restrictive than the access modifier of the superclass method
if the superclass method is public, the overriding method must be public
if the superclass method is protected, the overriding method may be protected or public
if the superclass method is package, the overriding method may be packagage, protected, or public
if the superclass methods is private, it is not inherited and overriding is not an issue
- the throws clause of the overriding method may only include exceptions that can be thrown by the superclass method, including it's subclasses
|