String knock = "\u042F \u0418\u0433\u043e\u0440\u044c";
SCJA 6 (Studying for SCJP 6)
Jason Hardaway wrote:
Unfortunately, the compiler is still complaining. Here is what it says now:
C:\Java\src\HF2\ch7>javac TestBoats2.java
TestBoats2.java:5: non-static variable this cannot be referenced from a static context
Boat b1 = new Boat();
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Matthew Brown wrote:
Jason Hardaway wrote:
Unfortunately, the compiler is still complaining. Here is what it says now:
C:\Java\src\HF2\ch7>javac TestBoats2.java
TestBoats2.java:5: non-static variable this cannot be referenced from a static context
Boat b1 = new Boat();
What you've done there is convert all your other classes into inner classes - they are defined within the TestBoats2 class.
You might not have come across inner classes yet, but when you study them you'll find that they need to be created from an instance of the parent class. In other words, you'd need to create a TestBoats2 object before you create a Boat object.
You could fix it by turning them into static inner classes (also known as nested classes). So, for instance, the declaration becomes public static class Boat. But, to be honest, you're better off with the final approach you say works. One file per public class is the way to go. When you've studied inner classes you might want to come back to this example, though, as you'll understand better why it isn't working.
SCJA 6 (Studying for SCJP 6)
Jared Malcolm wrote:
Personally I would have recommended following this route. Instantiating your TestBoats2 class and then using the constructor (which is non static) to create your different objects.