Question

In: Computer Science

Discuss the concept of parameters. What are parameters for? What is the difference between formal parameters...

Discuss the concept of parameters. What are parameters for? What is the difference between formal parameters and actual parameters? Give an example in Java code that illustrates formal parameters and actual parameters.

Solutions

Expert Solution

Parameters:

The data that is received by the method is known as a parameter.

For example:

void add(int a, int b);

In the above method, 'a' and 'b' are parameters.

When we call a method and want to pass some information to the called function then we use parameter. So, the parameters are used to pass the information.

Formal Parameter:

In a method, the identifier that is used to store the value passed by the calling method is the formal parameter.

void add(int a, int b);

In the above method, 'a' and 'b' are formal parameters.

Actual Parameter:

In a calling method, the actual value passed into the method is the actual parameter.

add(10, 20);

In the above method, '10' and '20' are actual parameters.

Difference between actual parameter and formal parameter:

  • The formal parameters are included in the function definition and the actual parameters are included in the function calling statement.
  • The formal parameter needed data type but there is no need for a data type in the actual parameter.
  • The formal parameters are variables but the actual parameter may be expression or variable or constant without data type.

For example:

public class Main
{
//method to add two numebrs
//the variable 'a' and 'b' are formal parameter
public static int add(int a, int b)
{
return a+b;
}
   public static void main(String[] args)
   {
   //method calling
   //'10' and '20' are actual parameter
   int c = add(10, 20);
  
   //display sum
       System.out.println("Sum = " + c);
   }
}


Related Solutions

What is authority? What is the difference between formal and informal authority? What is the difference...
What is authority? What is the difference between formal and informal authority? What is the difference between centralized and decentralized authority? Give an example of how authority works in an organization with which you are familiar, and explain whether or not it is effective.
Discuss the difference between the accountant's concept of profit and the economist's view of profit? 3....
Discuss the difference between the accountant's concept of profit and the economist's view of profit? 3. Profits or losses must be temporary for perfectly competitive firms. Why?
What is the difference between the concept of self control and impression management?
What is the difference between the concept of self control and impression management?
a- What is the main difference between the “net product” of the physiocrats and the concept...
a- What is the main difference between the “net product” of the physiocrats and the concept of value in Smith and Ricardo? b- How did Marx’s times help him develop his own specific labor theory of value? c- How does an individualist (selfish) conception of human nature affect an economic system of thought?
What is the difference between phenetic species concept and phylogenetic species concept? Which would do a...
What is the difference between phenetic species concept and phylogenetic species concept? Which would do a better job of categorising a new specie based on a color morph that is different from the rest of the species? and explain why?
2) Part A: Explain the concept of a Total Rewards Philosophy. Discuss the difference between rewards...
2) Part A: Explain the concept of a Total Rewards Philosophy. Discuss the difference between rewards and compensation. Why is it important to understand what motivates employees? Why do organizations provide both monetary and non-monetary rewards to employees? Use the articles and resources provided to support your ideas. Part B: Of the benefits discussed in chapter 7, list the ones you consider essential. Why are these benefits important to you?
What is the difference between "Classical Liberalism" as a concept and being considered a "Liberal" on...
What is the difference between "Classical Liberalism" as a concept and being considered a "Liberal" on the U.S. Political Spectrum? Ronald Reagan believed in small government. Based on my lecture, how was his belief somewhat, not entirely, contradictory? What is Fascism? Based on my lecture, which parts of Communism and Marxism are arguably still relevant today and which part(s) are not? What is the difference between "liberal democracy" and "social democracy"?
Discuss the concept of GDP (gross domestic product). Explain the difference between fiscal and monetary policy....
Discuss the concept of GDP (gross domestic product). Explain the difference between fiscal and monetary policy. Discuss the concept of the unemployment rate measurement. Discuss the concepts of inflation and deflation.  Explain other key terms: supply; demand; equilibrium price; monopoly; recession; depression.
Please answer all. 82. What is the difference between the accountant's concept of profit and the...
Please answer all. 82. What is the difference between the accountant's concept of profit and the economist's view of profit? 83.   Describe the types of entry barriers which can exist and their importance to the study of monopoly.
What are the difference between ethics and morality? Whey these two concept are important particularly in...
What are the difference between ethics and morality? Whey these two concept are important particularly in the context of quality management?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT