Reputation: 2896
I have a stupid confusion, when we override the parent class method then does this derived overridden method still hold the code of parent class method, or it is a new fresh method which we can define?
Upvotes: 3
Views: 2545
Reputation: 48592
Read this article to get concept clear. http://docs.oracle.com/javase/tutorial/java/IandI/override.html
Generally we do when we want to extend the method of super class or to want to change the complete logic.
For ex: Super class have sorting method which use bubble sort.
In Derived class you want to take same method but want to implement quick sort. Then we do overriding.
Second
If you want to execute super class method first then your sub class overriden method logic then we use super.methodname()
.
Last to point of your question If you override the method and not called super class method like super.method()
then its not mean its fresh method. Its means I already explain the sort example.
Upvotes: 7
Reputation: 12587
what happens is exactly what's written in the annotation.
you override the method and instead of running the parent code for the method, it runs the current class's code
Upvotes: 1