This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I went back few pages from the headfirst java book and tried a couple of excercise there.
On page 193 I tried to compile the correct code in the excercise on the compiler and I got:
non-static variable this cannot be referenced from a static context
The code is:
How do you make the following static?
Monster  ma = new Monster;
ma = new Vampire();
ma = new Dragon ();
ma = new Monster ();
I tried adding static in the beginning of each and that didn't work
Thanks in advance!
Apparently, what you don't know can hurt you...
That's because the mosters are inner classes of MonsterTestDrive thus can only be created with an instance of the enclosing class.
Creating an instance of MonsterTestDrive and then creating the monsters with that instance would be a solution but a better one would be to move the monster classes outside of the MonsterTestDrive class.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.