Method Overriding
- If subclass has the same method as declared in the parent class, it is known as method overriding
1. Usage
- Method overriding is used to provide specific implementation of a method that is already provided by its super class
- Method overriding is used for runtime polymorphism
2. Rule
- method must have same name as in the parent
- method must have same parameter
3. Problem without method overriding
- Problem is that I have to provide a specific implementation of run() method
4. Example
5. Question
1) Can we override static method?
- No, static method can't be overriden. It can be proved by runtime polymorphism
2) Why we can't overriden static method?
- Static method is bound with class whereas instance method is bound with object
- Static belongs to class area
- instance belongs to heap area
'Back-End > Java_1' 카테고리의 다른 글
[Java] Covariant Return type (0) | 2016.08.24 |
---|---|
[Java] Overloading vs Overriding (0) | 2016.08.24 |
[Java] Aggregation in java (0) | 2016.08.23 |
[Java] Inheritance in Java (0) | 2016.08.23 |
[Java] Input by Console (0) | 2016.08.23 |