• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HELP NEEDED FOR CALLING METHOD OF THE SAME CLASS

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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!
 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Yasser Shaikh
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!!
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please keep it down. Also Ease up
 
Jason Irwin
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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".



 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't even see any code that could generate that error.
 
Jason Irwin
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the code they have posted, no.

In the code they typed into their source file? Different question.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic