Re: WHY WONT THIS COMPILE!
For future reference, please use the code tags, and there is no need to shout (exclamation point, all caps). The compiler error is referring to the constructor in the parent class BankAccount, the defined constructore depends upon several parameters,
Code :
public BankAccount(double setBalance,String setName)
however the child class Tester does not contain this type of constructor. Any reason the class Tester extends BankAccount?
Re: WHY WONT THIS COMPILE!
if i dont extend it, i wont be able to use the variable in the first class, in my second class. As far as i know at least.
Re: WHY WONT THIS COMPILE!
Quote:
Originally Posted by
usmc0311
if i dont extend it, i wont be able to use the variable in the first class, in my second class. As far as i know at least.
What happened when you tried? And can't you just add a getter method?
Re: WHY WONT THIS COMPILE!
1) Are BankAccount and Tester in the same package/location? That might be why...if not:
2) Change your constructor to have different arguments.
instead of
Code :
BankAcount(double setBalance, String setName)
Also, in your second class, your last line of code is displaying the variable "x", not "o1.balance"
And as Kevin said, you should be able to access the variables using name.variable as long as you set them first (since you don't have a default value assigned)...
Re: WHY WONT THIS COMPILE!
Quote:
Originally Posted by
wrightm96
1) Are BankAccount and Tester in the same package/location? That might be why...
No, copeg already explained the cause. It has nothing to do with package or location.
Quote:
Originally Posted by
wrightm96
if not:
2) Change your constructor to have different arguments.
instead of
Code :
BankAcount(double setBalance, String setName)
No, that's not the correct solution. It might get rid of the error, but it causes other, more fundamental problems in the program's design.
Quote:
Originally Posted by
wrightm96
Also, in your second class, your last line of code is displaying the variable "x", not "o1.balance"
Right, but that's after he set balance equal to x, so it shouldn't matter that much.
Quote:
Originally Posted by
wrightm96
And as Kevin said, you should be able to access the variables using name.variable as long as you set them first (since you don't have a default value assigned)...
That is not what I suggested, and it's not even really true. Variable access has nothing to do with when you set them. It has more to do with access (private, public, packages, etc).
I appreciate that you're trying to help, but providing false information is not helpful.
Re: WHY WONT THIS COMPILE!
Just curious, being a junior in High School myself, what is the name of the course (is it AP, standard, honors, etc.)
Ok, now on to your problem:
1. Copeg makes a good point, there is no particular reason for Tester to extend BankAccount. All of BankAccount's variables and methods are public. You may be better off creating a BankAccount object rather than a Tester. However, since this is likely for school, you may be required to make Tester a child of BankAccount so...
2. If you absolutely need Tester to extend BankAccount try making a call to BankAccount's constructor using super Using the Keyword super (The Java™ Tutorials > Learning the Java Language > Interfaces and Inheritance)
That should be enough to get you started