Q:

Bank function, where new account gets $5, but when the withdraw is larger than balance, it doesnt take away the balance and gives error

public class Acc{                                       
  private double balance;                                       

  public Account()                                      
  {                                     
    balance = 5;                                        
  }                                     

  public Acc(double sBalance)                                       
  {                                     
    balance = sBalance;                                     
  }                                     

  public void depos(double amount)                                      
  {                                     
    balance = balance + amount;                                     
  }                                     
  public void withd(double amount)                                      
  {                                     
    balance = balance - amount; 
    if (withd>balance){
       System.out.println("Error");
      }     
  }                                     

  public double gBalance()                                      
  {                                     
    return balance;                                     
  }                                     

}

Main:
public class Main{                                      
  public static void main(String[] args){                                       
    Acc newBank = new Acc(50);                                      
    newBank.withd(20);                                      
    newBank.depos(5);                                       
    System.out.println(newBank.gBalance());                                     
  }                                     
}

Basically I wanted to create a function to withdraw and deposit a value from stored in balance, where $5 is added to every new account created. It seems to work, however I wanted to extend and make it so withdrawing more than the balance amount would give an error and not take away from the balance

A:

First, there are inconsistencies in the code you provided, which makes it impossible to compile:

The first constructor is public Account() while the class name is Acc
As pointed out by @Andy Turner, you are using the method name withd in the condition. It should rather be amount > balance.

If I understand what you are trying to do, the withdraw method should be:
public void withd(double amount)                                      
  {
      if (amount > balance) {
        System.out.println("Error");
      } else {
        balance = balance - amount;  
      }
  }

where you check if the balance has enough money before performing the withdraw.

