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.
1An abstract method is the method which does’nt have any body.
2Abstract method is declared with
3keyword abstract and semicolon in place of method body.
4
5 public abstract void <method name>();
6Ex : public abstract void getDetails();
7It is the responsibility of subclass to provide implementation to
8abstract method defined in abstract class
1public abstract class Account { //abstract class //perent class
2 protected int accountNumber;
3 protected Customer customerObj;
4 protected double balance;
5 //constructor
6 public Account(int saccountNumber, Customer scustomerObj,double sbalance){
7 accountNumber = saccountNumber;
8 customerObj = scustomerObj;
9 balance = sbalance;
10 }
11 // abstract Function
12 public abstract boolean withdraw(double amount);
13}
14
15public class SavingsAccount extends Account { // child class
16 private double minimumBalance;
17 // constructor
18 public SavingsAccount(int saccountNumber, Customer scustomerObj, double sbalance, double sminimumBalance) {
19 super(saccountNumber, scustomerObj, sbalance);
20 minimumBalance = sminimumBalance;
21 }
22 // Implementation of abstract function in child class
23 public boolean withdraw(double amount) {
24 if (balance() > minimumBalance && balance() - amount > minimumBalance) {
25 super.setBalance(balance() - amount);
26 return true;
27 } else {
28 return false;
29 }
30 }
31}
32
33
1Sometimes we may come across a situation
2where we cannot provide implementation to
3all the methods in a class. We want to leave the
4implementation to a class that extends it.
5 In that case we declare a class
6as abstract by using abstract keyword on method
7signature.In my framework I have created my
8PageBase class as super
9class of the all page classes.
10I have collected all common elements
11and functions into PageBase class and
12all other page classes extent PageBase class.
13By doing so, I don't have to locate very
14common WebElements and it provides
15reusability in my framework.
16
17i)List<String> webs=driver.getWindowHandles();
18=>create a list first to store web URLs in list
19
20ii)findElements evaluates multiple elements so therefore will assigned to List <WebElement>
21
22iii)To handle dynamic elements store it in the list and identify by index:
23List<WebElement> all=driver.findElements(By.tagname(“”)); (or other locators).
24Also
251)Abstract classes cannot be instantiated
262)An abstarct classes contains abstract method,
27concrete methods or both.
283)Any class which extends abstarct class must
29 override all methods of abstract class
304)An abstarct class can contain either
31 0 or more abstract method.