• Post Reply Bookmark Topic Watch Topic
  • New Topic

Call a method from another class  RSS feed

 
John Joe
Ranch Hand
Posts: 430
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I call create() method in Calculation class from Main class where ?

Calculation
Main




 
Ganesh Patekar
Bartender
Posts: 726
23
Eclipse IDE Hibernate jQuery MySQL Database Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would you please post your complete code?
so far what I understood you want to call Or invoke create() method from Main class which belong to Calculation class, am I correct?
John Joe wrote:where the create() function belongs to Summary class ? 
Are you sure about this? whatever code you posted above It shows method create() belongs to Calculation class because It is defined in Calculation class.
Did you notice method create() has private access modifier and needs to return something which you seem missing?

If you haven't gone through --> Access modifiers and Methods in Java these tutorials then please go through them first It might help you to clear these doubts.
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, it would be better to post code which will compile. There is a compile time error in the first code you posted.
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ganesh Patekar wrote:. . . method create() has private access modifier . . .
I hadn't noticed that error. Wouldn't that produce a different compiler error message about private access?
 
Ganesh Patekar
Bartender
Posts: 726
23
Eclipse IDE Hibernate jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Wouldn't that produce a different compiler error message about private access?
I see, I didn't pay attention to the comment. Yes It'll produce different compiler error message for private access modifier, also another error message for the method create() not returning an object of Summary type.
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In which case how can you get a cannot find symbol error message? Is there another error we haven't seen? If we haven't seen the real code and all of it, how are we to help?
 
Ganesh Patekar
Bartender
Posts: 726
23
Eclipse IDE Hibernate jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:In which case how can you get a cannot find symbol error message? Is there another error we haven't seen? If we haven't seen the real code and all of it, how are we to help?
It seems compiler can't find the definition of identifier Calculation so getting cannot find symbol error message, perhaps not imported but as you said without real code not possible to help.
 
David Simkulette
Ranch Hand
Posts: 67
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Joe wrote:How can I call create() method in Calculation class from Main class where ?

Calculation
Main






create is a private method of Calculation. If you main is outside Calculation, it's not going to see it.  Not sure which compiler or runtime or IDE you're using so compile / runtime  / static analysis (the stuff your IDE tells you is wrong about your code) messages might differ based on any of those.

Error message tell programmers a lot about where to look for mistakes so it's always good to post those even though they seem cryptic!
 
John Joe
Ranch Hand
Posts: 430
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys ! After changing private to public, it able to access now
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!