ICSE Class 9 Computer Applications
Question 2 of 10
Working with Methods — Question 2
Back to all questions 2
Question Question 2
How do you define and invoke a method?
The syntax of a method definition is:
[access-modifier] type method-name (parameter-list)
{
method-body;
}
To invoke a method, write the name of the method and specify the value of arguments of its parameter list. Below example shows the definition and invocation of a method:
public class DisplayMessageDemo {
public void DisplayMessage() {
System.out.println("Hello World!");
}
public void MyMessage() {
DisplayMessage();
}
}