• Post Reply Bookmark Topic Watch Topic
  • New Topic

Method call for a void method  RSS feed

 
Alice Hampton
Ranch Hand
Posts: 217
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've never had to do a void method call. I have my void method in one class and my main (where I want to do the call) in another. How do you actually call a void method?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like any other method, except that -since it has no return value- it's not assigned to a variable: object.method();
 
Alice Hampton
Ranch Hand
Posts: 217
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for replying!

What is object supposed to represent,as all you can do with object is object.class
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't mean java.lang.Object - that's just whatever object reference you're invoking the method on. If yours is called "alice", it would be "alice.method()"
 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or, if the method is static it is: NameOfYourClass.yourMethod().
 
Alice Hampton
Ranch Hand
Posts: 217
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys - just wanted to make sure that object meant something else rather than you meaning me actually use object,never harms to make sure you understand what the other person means fully

Both been very helpful!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!