Answers for "abstract in java"

2

how to make abstract method in java

public abstract class Account {		//abstract class //perent class
    protected int accountNumber;
    protected Customer customerObj;
    protected double balance;
  	//constructor
  	public Account(int saccountNumber, Customer scustomerObj,double sbalance){
        accountNumber = saccountNumber;
        customerObj = scustomerObj;
        balance = sbalance;
    }
  	// abstract Function
    public abstract boolean withdraw(double amount); 
}   

public class SavingsAccount extends Account { // child class
    private double minimumBalance;
  	// constructor
    public SavingsAccount(int saccountNumber, Customer scustomerObj, double sbalance, double sminimumBalance) {
        super(saccountNumber, scustomerObj, sbalance);
        minimumBalance = sminimumBalance;
    }
	// Implementation of abstract function in child class
    public boolean withdraw(double amount) {
        if (balance() > minimumBalance && balance() - amount > minimumBalance) {
            super.setBalance(balance() - amount);
            return true;
        } else {
            return false;
        }
    }
}
Posted by: Guest on March-30-2021
2

abstract class example in java

//abstract parent class
abstract class Animal{
   //abstract method
   public abstract void sound();
}
//Dog class extends Animal class
public class Dog extends Animal{

   public void sound(){
	System.out.println("Woof");
   }
   public static void main(String args[]){
	Animal obj = new Dog();
	obj.sound();
   }
}
Posted by: Guest on November-11-2020
2

abstract class 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

what are abstract classes 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.

i)List<String> webs=driver.getWindowHandles();
=>create a list first to store web URLs in list

ii)findElements evaluates multiple elements so therefore will assigned to List <WebElement>

iii)To handle dynamic elements store it in the list and identify by index:
List<WebElement> all=driver.findElements(By.tagname(“”)); (or other locators).
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-22-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language