![]() |
alternative to this code?
is there a way that i can get rid of having to make a class static that i declare an object of in the main method?
like i made this program to practice utilizing abstract classes by the way, it works PERFECTLY without errors WITH the bolded code. :
import java.util.Random;:
non static variable cannot be referenced from a static contexti heard something about making the class non public; would this do anything? i tried it and i get other errors... |
Ship is an abstract class, and as such should not contain any method definitions, including main.
Inner classes should (for the most part) only be used when the inner class will be used only by the outer class. Moreover, an inner class should be thought of as part of its outer class; a Battleship is a Ship, not part of one. Battleship objects should be be created outside the Ship object. You need to divide your code into three classes: Ship.java; Battleship.java; and Main.java (the naming of this last class is arbitrary), which might read: :
public class Main { |
Quote:
|
Quote:
|
yeah i understand what you said, no confusion :)
what daemon said is right and since i DID use teh constructor super(name) which uses the abstract classes constructor, it has a use. thank you so much though titanium i realize how easy this was lol im stupid... |
| All times are GMT -5. The time now is 2:03 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC