Answers for "why use an abstract class"

2

is it necessary for abstract class to have abstract method

Abstract classes CAN have non-abstract methods.
Posted by: Guest on August-27-2021
2

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.
Posted by: Guest on May-28-2021
0

can you declare an abstract method in a non abstract class

No. A normal class(non-abstract class) cannot have abstract methods.
Posted by: Guest on November-14-2020

Code answers related to "why use an abstract class"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language