72.9k views
2 votes
Modularizing Your Code". This technique is used to break a complex program into small, manageable modular pieces called Methods. A method is a collection of statements that performs a specific task. We learned that methods are mainly two types, the void methods and the value returning methods. Please discuss these two types. In your discussion cover the following

Discuss different examples that requires the use of the value returning method.
Argue whether we need both types or one is enough and can be used with all scenarios.

User Tolga E
by
7.2k points

1 Answer

5 votes

Final answer:

Void methods do not return a value, while value returning methods return a value after performing a specific task. Both types are important and serve different purposes in a program.

Step-by-step explanation:

A void method is a method that does not return a value. It is used when we only need to perform a task or action without expecting any result or output. For example, a void method can be used to display a message on the screen or update the value of a variable.

A value returning method, on the other hand, is a method that returns a value after performing a specific task. It is used when we need to calculate or retrieve a value that can be used in other parts of the program. An example of a value returning method is a mathematical function that calculates the square of a number and returns the result.

Both types of methods are important and serve different purposes. Void methods are useful for performing actions or tasks, while value returning methods are essential for performing calculations or retrieving data. Depending on the specific requirements of a program, we may need to use both types of methods in order to achieve the desired functionality.

User Hotaka
by
7.9k points