Answers for "abstraction and interface in java"

4

abstraction in java

Abstraction is nothing but the quality of dealing with ideas rather than 
events. It basically deals with hiding the internal details and showing 
the essential things to the user.
Posted by: Guest on June-22-2020
2

what is abstraction in java

Sometimes we may come across a situation
where we cannot provide implementation to
all the methods in a class. We want to leave the 
implementation to a class that extends it.
  In that case we declare a class
as abstract by using abstract keyword on method
signature.In my framework I have created my
PageBase 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)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 January-05-2021
1

Abstraction in java

// example on abstract class in java
import java.util.*;
// abstract class
abstract class Shape
{
   // abstract method
   abstract void sides();
}
class Triangle extends Shape
{
   void sides()
   {
      System.out.println("Triangle shape has three sides.");
   }
}
class Pentagon extends Shape
{
   void sides()
   {
      System.out.println("Pentagon shape has five sides.");
   }
   public static void main(String[] args)
   {
      Triangle obj1 = new Triangle();
      obj1.sides();
      Pentagon obj2 = new Pentagon();
      obj2.sides();
   }
}
Posted by: Guest on November-23-2020
0

abstraction example in java

In my framework I have achieved abstraction 
by using collections or Map, because it’s all interface. 
  Most of the cases I come   across using List. 
  If we want to access elements frequently by using index, 
List is a way to go. ArrayList provides faster access if we know index. 
  If we want to store elements and want them to maintain an order, 
List is a better choice. 
i) List webs = driver.getWindowHandles(); 
=>create a list first to store web URLs in list
ii) findElements evaluates multiple elements 
so therefore will assigned to List 
iii) To handle dynamic elements store it in the list and identify by index: 
List all = driver.findElements(By.tagname(“”));
In my framework I follow POM and had situations 
where some pages shared similar actions that were similar 
but worked slightly different, so I was able to use abstraction 
to define those actions and implement them in each page according 
to what was needed for that webpage
Posted by: Guest on May-28-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language