This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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!
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.
Joined: Oct 01, 2008
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
C:\Documents and Settings\RNS\My Documents\TestShape.java:36: non-static method doShape(GameShape) cannot be referenced from a static context
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".