Why are we using abstract class and interface ? | Selenium Forum
J
janmay87 Posted on 02/08/2019
Please help me to understand this concents in details. 1.Like when we should use abstract class and and interface while programming ? 1. Can we create the object of abstract class and interfaces and if not then why we can't ? 2. In case of automation how both these concepts are useful ?

A
Ashish Thakur Replied on 07/08/2019

Answers to your questions:

1: No, we cannot create the object of Interface as well as Abstract Class.

In the case of Interface, we need to create an implementing class which implements all the methods specified by the Interface. The object of that class can be created and can be used.

In the case of Abstract class, we need to create an extending class which implements all the remaining methods specified by the Interface. After that, we can create the object of the extending class.

 

2: These concepts are useful in automation as interface provides the basic frame to the code which needs to be described by each implementing class. In the case of Abstract class, this tells us that few things are implemented and few are remaining which needs to be completed. For example, two classes share the same piece of code. In that case, we can make use of the abstract class to implement those and can describe the remaining methods.