No. The program will not compile.
The main()
method cannot use the private variable useCount
nor can it use the private
method incrementUse()
.
These can only be used by the other methods of the object.
Here is what the compiler outputs for the mistaken program:
The main()
method can use the public method bobsAccount.processCheck()
which in turn uses the private method incrementUse()
.
compiling: CheckingAccountTester.java CheckingAccountTester.java:55: No method matching incrementUse() found in class CheckingAccount. bobsAccount.incrementUse(); ^ CheckingAccountTester.java:56: Variable useCount in class CheckingAccount not accessible from class CheckingAccountTester. bobsAccount.useCount = 15; ^ 2 errors
Should you fix these compiler errors by making useCount
and incrementUse()
public
?