Question

In: Computer Science

Please discuss the importance of providing parameters to methods and describe how a parameter is declared...

  1. Please discuss the importance of providing parameters to methods and describe how a parameter is declared within a method header. Give examples.
  2. Please describe the features of methods, including the number of methods permitted in a program, method naming rules, the composition of a method, and variable scope rules. Please give an example of each one.

Solutions

Expert Solution

the importance of providing parameters to methods.

Ans.  

Parameters/Arguments, essentially, are values that are passed into functions.

Without parameters, methods become pretty much useless. How would I be able to find the sum of n1 & n2 using the sum() function without knowing n1 & n2? That dilemma is pretty trivial but it can get even more complex.

describe how a parameter is declared within a method header. Give example.

Ans.

A method is just a chunk of code that does a particular job. But methods are set out in a certain way. You have a method header, and a method body. The header is where you tell Java what value type, if any, the method will return (an int value, a double value, a string value, etc). As well as the return type, you need a name for your method, which also goes in the header. You can pass values over to your methods, and these go between a pair of round brackets. The method body is where you code goes.

  

int myMethod(int x, int y) {
    return x + y;
  }

Describe the features of methods.

Ans.

A method is a block of code which only runs when it is called.

You can pass data, known as parameters, into a method.

Methods are used to perform certain actions, and they are also known as functions.

To call a method in Java, write the method's name followed by two parentheses () and a semicolon

myMethod() is the name of the method.

void means that this method does not have a return value.

A method can also be called multiple times.

number of methods permitted in a program.

Ans.

No fixed number of methods for a program you can make as much as you want

method naming rules.

Ans.

Methods should be verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized.

eg.  run();
runFast();
getBackground();

the composition of a method

Ans.

Composition is one of the fundamental concepts in object-oriented programming. It describes a class that references one or more objects of other classes in instance variables. This allows you to model a has-a association between objects.

eg.

You can find such relationships quite regularly in the real world. A car, for example, has an engine and modern coffee machines often have an integrated grinder and a brewing unit.

uses:

  1. reuse existing code
  2. design clean APIs
  3. change the implementation of a class used in a composition without adapting any external clients

variable scope rules.

Ans.

Variable Scope means - That limit, as far as the variable can be used.

  • Local variables
  • Instance variables
  • Class/Static variables

Local variables

A variable that is declared within the method that is called local variables. It is defined in method or other statements, such as defined and used within the cache block, and outside the block or method, the variable cannot be used.

Instance variables

A non-static variable that is declared within the class but not in the method is called instance variable. Instance variables are related to a specific object; they can access class variables.

Class/Static variables

A variable that is declared with static keyword in a class but not in the method is called static or class variable.

eg.

public class Example

{

int salary; // Instance Variable

public void show() {

int value = 2; // Local variable

value = value + 10;

System.out.println("The Value is : " + value);

salary = 10000;

System.out.println("The salary is : " + salary); }

public static void main(String args[]) {

Example eg = new Example();

eg.show();

}

}

THANK YOU.


Related Solutions

Can you discuss the following water quality parameters: what components determines each parameter and please give...
Can you discuss the following water quality parameters: what components determines each parameter and please give examples - pH -Alkalinity -Hardness -Turbidity -Natural Organic matter -Total dissolved solids -Dissolved Oxygen -Water Microbiology
Discuss the importance of sampling, and articulate how sampling is related to parameter estimation. Provide practical...
Discuss the importance of sampling, and articulate how sampling is related to parameter estimation. Provide practical examples that support your arguments (e.g. examples of how appropriate sampling can provide better parameter estimates for your population you are studying).
Discuss the t test and p value as a means of determining importance of regression parameters.
Discuss the t test and p value as a means of determining importance of regression parameters.
(a) Discuss how an actual parameter is related to its corresponding formal parameter in the following...
(a) Discuss how an actual parameter is related to its corresponding formal parameter in the following four parameter-passing methods for procedure calls. a. Pass by value b. Pass by reference c. Pass by name (b) Given the output of the following program (written in C syntax) using the above three parameter-passing methods: int i, j, a[5]; // a is a 5 element array with indices 0 - 4 void swap(int x, int y) { int temp = x; x =...
Discuss the importance of providing accurate financial information. What is the impact of inaccurate information? Who...
Discuss the importance of providing accurate financial information. What is the impact of inaccurate information? Who is looking at this information and why? How do the challenges of providing accurate financial information impact the health care business that you have chosen to create in this course? What legal ramifications could result from disseminating inaccurate information?
Write discuss the methods of development that were used in "The Importance of Health Education" By...
Write discuss the methods of development that were used in "The Importance of Health Education" By Marcy Vadurro's article by bringing the examples.
Please answer the list of questions below: 1. Discuss the importance of financial statements and how...
Please answer the list of questions below: 1. Discuss the importance of financial statements and how they are used by businesses. 2. What is the basic format of the income statement and what is the relevance of the basic categories? 3. Cash flows for an organization come from operating activities and investment activities. Discuss the importance of each to the organization. 4. The Happy Auto Shop has the following annual information: Gross Sales $700,000 Net sales $696,000 Gross profit $448,000...
Ventilation-perfusion mismatch. Please explain in your own words, the importance of or relevance of the V/Q parameter.
Ventilation-perfusion mismatch. Please explain in your own words, the importance of or relevance of the V/Q parameter. Please highlight its importance as a mathematical parameter in our mass transport models as well as its implications to clinical performance and pathologies. Max of 400 words.
Ventilation-perfusion mismatch. Please explain in your own words, the importance of or relevance of the V/Q parameter.
Ventilation-perfusion mismatch. Please explain in your own words, the importance of or relevance of the V/Q parameter. Please highlight its importance as a mathematical parameter in our mass transport models as well as its implications to clinical performance and pathologies. Max of 400 words.
please answer this question!!! 4) Describe how scale influences the estimation of hydraulic parameters obtained from...
please answer this question!!! 4) Describe how scale influences the estimation of hydraulic parameters obtained from core samples, slug tests and pumping tests. which method tends to produce the most reliable estimates? why?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT