Welcome to ICSE Java Answers. Ask any questions you have related to Java and we will answer them.
Java is a registered trademark of Oracle. This site is in no way related to or endorsed by Oracle.

What are the different ways to invoke a function or a method?

0 votes
asked by Shashank (48 points)

2 Answers

0 votes
If the method is non-static, it can be invoked only on an object of the class in which it is defined.

If the method is static, it can be invoked either using the class name or an object of the class.

The following page contains an example - http://www.icsejavatutorial.com/answers/608/what-is-static-member-method
answered by Ranjith (2,103 points)
0 votes

I will provide the examples. First, for the non-static method:

Car car = new Car();//initialising object
car.carName(arg0,arg1...);

In the  first line,  I am creating an object named "car" in the class Car. Then, in the second line, I am calling the non-static function of Car carName, and passing parameters to the carName function, in the same order as in the method parameter list. The other way is by calling the function directly, although it could be done only by another non-static method. Here, we just write the name of the function

public void carCode{
carName();
}

Here we could also pass parameters in the same manner.

A static method could be called by the classname, or an object of the clas and Ranjith said.

answered by Soham Thakurata (333 points)
...