aspose file tools*
The moose likes Beginning Java and the fly likes HELP NEEDED FOR CALLING METHOD OF THE SAME CLASS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "HELP NEEDED FOR CALLING METHOD OF THE SAME CLASS" Watch "HELP NEEDED FOR CALLING METHOD OF THE SAME CLASS" New topic
Author

HELP NEEDED FOR CALLING METHOD OF THE SAME CLASS

Yasser Shaikh
Greenhorn

Joined: Oct 01, 2008
Posts: 21

Outputs:
displaying shape
displaying shape

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
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
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!!
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10376
    
    8

Please keep it down. Also Ease up


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Jason Irwin
Ranch Hand

Joined: Jun 09, 2009
Posts: 327
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".



David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I don't even see any code that could generate that error.
Jason Irwin
Ranch Hand

Joined: Jun 09, 2009
Posts: 327
In the code they have posted, no.

In the code they typed into their source file? Different question.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HELP NEEDED FOR CALLING METHOD OF THE SAME CLASS