this is what i found in my scjp book while studying ...
but when i was trying to run this piece of code on my pc i got an error...
which i then corrected by just creating an object of the TestShape class
and calling doShapes method with that object...
please guide me!
~~yr[:_:]s~~
Jason Irwin
Ranch Hand
Joined: Jun 09, 2009
Posts: 327
posted
0
What is it you do not understand?
The code from K&B works as it is written in the book (SCJP6, Chapter 2, Inheritance, Is-A, Has-A, page 91), I get no exceptions, just he output as described. What exception did you get?
I can't see why you need an instance of TestShape - it's static methods you are calling and they do not require an object instance, they can be called on the class instance.
SCJP6
Yasser Shaikh
Greenhorn
Joined: Oct 01, 2008
Posts: 21
posted
0
No... i dont get exceptions i got two errors they are listed below:
C:\Documents and Settings\RNS\My Documents\TestShape.java:35: non-static method doShape(GameShape) cannot be referenced from a static context
doShape(player);
^
C:\Documents and Settings\RNS\My Documents\TestShape.java:36: non-static method doShape(GameShape) cannot be referenced from a static context
doShape(tile);
^
2 errors
and didnt get what you are trying to say...
its not the static method that i am callin ....
doShapes() is a non-static method...
please reply ASAP!!
Yasser - the code you presented here works perfectly and "doShapes" is static, but in your program you get an error. What does that tell you?
Your program has at least two mistakes in it.
1) There should be no "doShape" method, but should be a "doShapes" method.
2) Carefully check your declaration of the "doShapes" method. I think you'll find something missing. Clue: it begins with "s".