is it necessary for abstract class to have abstract method
Abstract classes CAN have non-abstract methods.
is it necessary for abstract class to have abstract method
Abstract classes CAN have non-abstract methods.
abstract class
Abstract class is used in defining a common super
class while writing Page Object Model layer of the
framework. We usually create an abstract class named
BasePage to have all common members for every page written
in this class example getPageTitle().
Then each Page class (HomePage, LoginPage, DashboardPage
etc.) inherit from BasePage.
Sometimes one may need to change the behavior of methods
implemented in superclass. So, subclass has freedom to
override that method where we use polymorphism.
This is how we use Abstract class in real projects.
.In my framework I have created my
BasePage class as super
class of the all page classes.
I have collected all common elements
and functions into PageBase class and
all other page classes extent PageBase class.
By doing so, I don't have to locate very
common WebElements and it provides
reusability in my framework.
Also
1)Abstract classes cannot be instantiated
2)Abstract class meant to be inherited
so can not be final,static and private
2)An abstarct classes contains abstract method,
concrete methods or both.
3)Any class which extends abstarct class must
override all methods of abstract class
4)An abstarct class can contain either
0 or more abstract method.
what is the need of abstract class
It is helpful if you need to make a generic function that can take a lot of class types as an argument. Eg:
abstract class Shape {
void area();
void perimeter();
}
class Rectangle extends Shape {
int width;
int height;
Rectangle(this.width, this.height);
void area() => this.width * this.height;
void perimeter() => 2*(this.width + this.height);
}
class Triangle extends Shape {
int side1;
int side2;
int side3;
Triangle(this.side1, this.side2, this.side3);
void area() => 0.5 * this.side1 * this.side2 * this.side3;
void perimeter() => this.side1 + this.side2 + this.side3;
}
void printGeometry(Shape shape) {
print("The area of this shape is ${shape.area()}";)
print("The perimeter of this shape is ${shape.perimeter()}";)
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us