ICSE Class 10 Computer Applications Question 3 of 43

User-Defined Methods — Question 3

Back to all questions
3
Question

Question 3

How do you define and invoke a method?

Answer

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();
    }
}