Question:

How do I call methods in Java? I can make the methods, but what do I put before the .methodToInvoke(); ?

by  |  earlier

0 LIKES UnLike

And please give some examples? x?x?x.methodName();

I usually try to make static methods to avoid this, but that doesn't always work. So what do I use, as I cannot use primitive types?

 Tags:

   Report

3 ANSWERS


  1. Why don't you just use this.methodName();?


  2. Ok, I think you need to start over. Methods belong to the objects, so if you have and object you should be able to call its built in methods like toString() which converts most obects to a string format so you can see the attributes of the object. Making the methods static means that only that class or objects that extent that class can call that method(I think that if they belong to the same package you can still call them too). Primitive types can be the attributes of the object, but then you should have a getter and setter for them. I am not sure if I understand what you are asking, but I hope this helps you understand OOL.

  3. if the method is located in the same class, you can put nameOfMethod(); and that's it

    if the method is located in another class for example Test.class yo can invoke it by typing  Test.nameOhMethod();

Question Stats

Latest activity: earlier.
This question has 3 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.