We have seen how inheritance works in TestNg classes in this post. In this post, we will see how overriding works in inherited TestNG classes.
Create a super class as below:
Now create a sub class where we will override one method from super class as below:
Let’s run subclass as a testng test:
You can see that only overridden methods in subclass got executed. In this post , we learnt that TestNG prioritized and execute methods of super class and subclass separately. But if some methods are overridden, only overridden method will be executed and parent method of super class will be ignored. If you have better understanding of overriding concept in java, then it is similar to calling super class method using sub class reference.
More about TestNG in upcoming posts. Stay tuned.
If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.