I trying to learn Java from "Java A Beginners Guide" Fifth Edition by Herber Schildt. In the fourth chapter he has this program that I copied and compiled but I get errors from his example. Because I am new I do not know how to fix the problems. Here is the program.
I am using the latest Eclipse and on line 3 Eclipse is saying "The type Vehicle is already defined".
On line 31 Eclipse is stating "Exception in thread "main" java.lang.NoSuchFieldError: fuelcap
These are things I don't understand how to fix and I would like someone to help repair the code so it actually works. Thanks
That is a pretty dreadful design you have been given, and I have seen similar in other books. The fields should have private access in the Vehicle class, and should be initialised via the constructor. If you want to display them in other classes, they can be made accessible via public getXXX methods.