does a java class need a constructor, in this code there does not seem to be any constructor?
Code:class CheckingAccount { private double balance = 0; public void setBalance(double bal) { balance = bal; }; public double getBalance(){ return balance; }; } class Encapsulation { public static void main(String args[]) { System.out.println("Starting myEncapsulation..."); CheckingAccount myAccount = new CheckingAccount(); myAccount.setBalance(40.00); System.out.println("Balance = " + myAccount.getBalance()); } }
in the code line
does the checkingaccount() call a function or does it call the class since there is a pari of brackets at the end of the codeCode:checkingaccount myaccount = new checkingaccount();




Reply With Quote