Super keyword
- The super keyword is a reference variable that is used to refer immediate parent class object
1. Usage
- super is used to refer immediate parent class instance variable
- super() is used to invoke immediate parent class constructor
- super is used to invoke immediate parent class method
2. parent class instance variable
- 50
3. To invoke parent class constructor
- vehicle, bike
- super() is added in each class constructor automatically by compiler
- If In the above example Bike doesn't have a super(), It will print out same result
4. To invoke parent class method
- It should be used in case subclass contains the same method as parent class
- In case there is no method in subclass as parent, there is no need to use super.
'Back-End > Java_1' 카테고리의 다른 글
[Java] Final keyword (0) | 2016.09.07 |
---|---|
[Java] Instance initializer block (0) | 2016.09.07 |
[Java] Covariant Return type (0) | 2016.08.24 |
[Java] Overloading vs Overriding (0) | 2016.08.24 |
[Java] Method Overriding (0) | 2016.08.24 |