Link to home
Start Free TrialLog in
Avatar of Troudeloup
Troudeloup

asked on

[noob][java] method void, int and others.

This is a noob code to practice some java code.

for use of method, even though the return type is void, it's still possible to modify the values of the object.

what are other return types for?






public class usebankaccount
{

      public static void main(String[] args)
      {
            
            bankaccount acct1 = new bankaccount();
            acct1.deposit(500);
            acct1.show();
            
            //  System.out.println ( acct1 );
            
      }
      
      
}




class bankaccount
{
      double penny;
                  
      
      public bankaccount()
      {
            System.out.println ("an account has been opened and it has 0 dollars.");
      }
      
      public bankaccount(double pennies)
      {
            double penny = pennies;
            System.out.println ("an account has been opened and it has" + penny + "dollars.");
      }
      
      public ba (double pennies)
      {
            double penny = pennies;
            System.out.println ( " An instance of the object ba has been created and " + penny + "is its balance." )
      }
            
            
      
      public void withdraw(double subtract)
      {
            penny = penny - subtract;
            System.out.println(subtract + "has been withdrew, the account still has" + penny + "dollars.");
            
      }
      
      public void deposit (double add )
      {
            penny = penny + add;
            System.out.println(add + "has been deposited, the account now has" + penny + "dollars.");
      
      }

      public void show()
      {
            System.out.println("This account has " + penny + " dollars.");
            
      }
      
      
}



SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Troudeloup
Troudeloup

ASKER

but what do they return?

since the addition or other operations can be done with void,

what are they for?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
you mean that whatever type the method is

class int intt()
{}

class void voida()
{}

they all return nothing?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
:-)