Questions On Learning Objectives And Outcomes

2098 Words9 Pages
LESSON 6: OVERRIDING METHODS LEARNING OBJECTIVES AND OUTCOMES • Introduction • Final variables and methods • Final classes • Finalizer methods INTRODUCTION In JAVA, method inheritance is used for defining and using methods repeatedly in subclasses without defining methods again and again in every subclass. Sometimes, it is required for an object to respond the same method but have different behavior when the method is called. This is achieved by defining a subclass method that has the same name, arguments and return type as the method in the superclass. This is termed as overriding the method in JAVA. So, when the method is called, the subclass method is invoked and executed rather than superclass method. The rules for method overriding are summarized below: • The argument list should be exactly same as that of the overridden method. • The return type should be the same or should be a subtype of the return type declared in the original overridden method in the superclass. • The access level cannot be more restrictive than the overridden method 's access level. • Instance methods can be overridden only if they are inherited by the subclass. • A method declared final cannot be overridden. • A method declared static cannot be overridden but can be re-declared. • If a method cannot be inherited, then it cannot be overridden. • A subclass within the same package as the instance 's superclass can override any superclass method that is not declared private or final. • A

More about Questions On Learning Objectives And Outcomes

Get Access