1Sometimes we may come across a situation where we cannot provide
2implementation to all the methods in a class. We want to leave the
3implementation to a class that extends it. In such case we declare a class
4as abstract.To make a class abstract we use key word abstract.
5Any class that contains one or more abstract methods is declared as abstract.
6If we don’t declare class as abstract which contains abstract methods we get
7compile time error.
8
9 1)Abstract classes cannot be instantiated
10 2)An abstarct classes contains abstract method, concrete methods or both.
11 3)Any class which extends abstarct class must override all methods of abstract
12 class
13 4)An abstarct class can contain either 0 or more abstract method.
1Interface
21) Interface contains only abstract methods
32) Access Specifiers for methods in interface
4must be public
53) Variables defined must be public , static ,
6final
74) Multiple Inheritance in java is implemented
8using interface
95) To implement an interface we use
10implements keyword
11
12Abstract Class
131) Abstract class can contain abstract methods,
14concrete methods or both
152) Except private we can have any access
16specifier for methods in abstract class.
173) Except private variables can have any access
18specifiers
194)We cannot achieve multiple inheritance using
20abstract class.
215)To implement an interface we use implements
22keyword
1Interfaces specify what a class must do and not how.
2It is the blueprint of the class.
3It is used to achieve total abstraction.
4
5We are using implements keyword for interface.
6
7Abstract=
8Sometimes we may come across a situation
9where we cannot provide implementation to
10all the methods in a class. We want to leave the
11implementation to a class that extends it.
12 In that case we declare a class
13as abstract by using abstract keyword on method
14signature.In my framework I have created my
15PageBase class as super
16class of the all page classes.
17I have collected all common elements
18and functions into PageBase class and
19all other page classes extent PageBase class.
20By doing so, I don't have to locate very
21common WebElements and it provides
22reusability in my framework.
23Also
241)Abstract classes cannot be instantiated
252)An abstarct classes contains abstract method,
26concrete methods or both.
273)Any class which extends abstarct class must
28 override all methods of abstract class
294)An abstarct class can contain either
30 0 or more abstract method.
31
1***************************Abstract class*****************************
21) Abstract class can have abstract and non-abstract methods.
32) Abstract class doesn't support multiple inheritance.
43) Abstract class can have final, non-final, static and non-static variables.
54) Abstract class can provide the implementation of interface.
65) The abstract keyword is used to declare abstract class.
76) An abstract class can extend another Java class and implement multiple Java interfaces.
87) An abstract class can be extended using keyword "extends".
98) A Java abstract class can have class members like private, protected, etc.
109)Example:
11public abstract class Shape{
12public abstract void draw();
13}
14
15
16*****************************Interface********************************
171) Interface can have only abstract methods. Since Java 8, it can have default and static methods also.
182) Interface supports multiple inheritance.
193) Interface has only static and final variable
204) Interface can't provide the implementation of abstract class.
215) The interface keyword is used to declare interface.
226) An interface can extend another Java interface only.
237) An interface can be implemented using keyword "implements".
248) Members of a Java interface are public by default.
259) Example:
26public interface Drawable{
27void draw();
28}
29
1Interfaces specify what a class must do.
2It is the blueprint of the class.
3It is used to achieve total abstraction.
4We are using implements keyword for interface.
5
6Basic statement we all know in Selenium is
7WebDriver driver = new FirefoxDriver();
8WebDriver itself is an Interface.
9So we are initializing Firefox browser
10using Selenium WebDriver.
11It means we are creating a reference variable
12of the interface and creating an Object.
13So WebDriver is an Interface and
14FirefoxDriver is a class.
15
16Abstract Class
171) Abstract class can contain abstract methods,
18concrete methods or both
192) Except private we can have any access
20specifier for methods in abstract class.
213) Except private variables can have any access
22specifiers
234)We cannot achieve multiple inheritance using
24abstract class.
1Interfaces specify what a class must do.
2It is the blueprint of the class.
3It is used to achieve total abstraction.
4We are using implements keyword for interface.
5
6Basic statement we all know in Selenium is
7WebDriver driver = new FirefoxDriver();
8WebDriver itself is an Interface.
9So we are initializing Firefox browser
10using Selenium WebDriver.
11It means we are creating a reference variable
12of the interface and creating an Object.
13So WebDriver is an Interface and
14FirefoxDriver is a class.
15
16Sometimes we may come across a situation
17where we cannot provide implementation to
18all the methods in a class. We want to leave the
19implementation to a class that extends it.
20 In that case we declare a class
21as abstract by using abstract keyword on method
22signature.For example in my framework I am using
23page object model design pattern and I keep all
24locators under Page class. I utilize this locators
25in tests but we can't see them in the tests.
26Literally we are hiding locators from the test.
27Abstraction is methodology of hiding implementation
28of internal details and showing the functionality to
29users.
30Also
311)Abstract classes cannot be instantiated
322)An abstarct classes contains abstract method,
33concrete methods or both.
343)Any class which extends abstarct class must
35 override all methods of abstract class
364)An abstarct class can contain either
37 0 or more abstract method.
38