// Example 3 of OOP -
constructor
public class oop3
{
public static void main(String[] args)
{
PiggyBank P = new PiggyBank(42,8,14,7); //
pennies, nickles, dimes, quarters
System.out.println("Piggy Bank has $" +
P.GetValue());
}
}
class PiggyBank
{
int Pennies, Nickles, Dimes, Quarters;
PiggyBank (int P, int N, int D, int Q)
{
Pennies = P; Nickles = N; Dimes = D; Quarters =
Q;
}
double GetValue()
{
return Pennies * 0.01 + Nickles * 0.05 + Dimes *
0.10 + Quarters * 0.25;
}
}