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(subtrac t + "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.");
}
}
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(subtrac
}
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
you mean that whatever type the method is
class int intt()
{}
class void voida()
{}
they all return nothing?
class int intt()
{}
class void voida()
{}
they all return nothing?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
:-)
ASKER
since the addition or other operations can be done with void,
what are they for?