Redefining a method in a subclass with the same signature as in its superclass.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Flip
Revise later
SpaceTo flip
If confident
All Flashcards
What is method overriding?
Redefining a method in a subclass with the same signature as in its superclass.
What is a superclass?
The class whose properties are inherited by another class.
What is a subclass?
A class that inherits properties from another class (superclass).
What does the `@Override` annotation signify?
Indicates that a method is overridden from a superclass.
What is method overloading?
Defining multiple methods with the same name but different parameters in the same class.
What is method signature?
The name and parameters of a method.
What does 'inherit' mean in OOP?
To receive properties and methods from a parent class.
Define 'implementation' in the context of methods.
The code that defines what a method does.
What are Javadoc comments?
Documentation comments used to generate API documentation.
What is the purpose of a constructor?
A special method used to initialize objects of a class.
Why is method overriding useful?
Allows a subclass to provide a specific implementation of a method already defined in its superclass.
When should you override a method?
When the subclass needs to behave differently than the superclass for a particular method call.
What happens if a subclass doesn't override a method?
The subclass inherits the superclass's implementation of the method.
Why are Javadoc comments often omitted in overridden methods?
The documentation is inherited from the superclass method.
What is the relationship between inheritance and overriding?
Inheritance provides the method, overriding allows specialized behavior in subclasses.
How does overriding promote polymorphism?
Allows objects of different classes to respond to the same method call in their own way.
What is the role of the `@Override` annotation?
It signals to the compiler that the method is intended to override a superclass method, catching errors if it doesn't.
Can a subclass override a private method of its superclass?
No, private methods are not accessible to subclasses and therefore cannot be overridden.
What is the difference between overriding and overloading?
Overriding replaces a superclass method, overloading creates a new method with the same name but different parameters.
How does overriding relate to the 'is-a' relationship?
A subclass 'is-a' type of its superclass, and overriding allows it to refine the superclass's behavior.
What are the differences between method overriding and method overloading?
Overriding: Same method signature in subclass. | Overloading: Same method name, different parameter list in the same class.
What are the differences between inheritance and overriding?
Inheritance: Acquiring properties/methods from a superclass. | Overriding: Modifying the implementation of an inherited method.
What are the differences between using `@Override` and not using it when overriding a method?
Using `@Override`: Compiler checks if method is actually overriding. | Not using `@Override`: No compiler check, potential for errors if not overriding correctly.
What are the differences between overriding a method and creating a new method in a subclass?
Overriding: Changes the behavior of an existing method. | New method: Adds new functionality specific to the subclass.
What are the differences between public and private methods in the context of overriding?
Public methods: Can be inherited and overridden. | Private methods: Cannot be inherited or overridden.
What are the differences between the effect of overriding and not overriding a method on a subclass object?
Overriding: Subclass object uses the overridden method's implementation. | Not overriding: Subclass object uses the superclass's implementation.
What are the differences between the scope of overridden methods vs. overloaded methods?
Overridden methods: Exist in superclass and subclass, same signature. | Overloaded methods: Exist in the same class, different signatures.
What are the differences between late binding and early binding in the context of overriding?
Overriding: Uses late binding (runtime) to determine which method to call. | Overloading: Uses early binding (compile time) to determine which method to call.
What are the differences between the use of `super` in overriding and not overriding?
Overriding: `super` can be used to call the superclass's implementation. | Not overriding: `super` is not relevant as the superclass method is not being redefined.
What are the differences between the purpose of overriding and the purpose of implementing an interface method?
Overriding: To change the behavior of an inherited method. | Implementing: To provide a concrete implementation for an abstract method defined in an interface.