0% found this document useful (0 votes)
2 views2 pages

Writing Methods Worksheet Guide

The document is a worksheet focused on writing methods in programming. It includes exercises for identifying code segments related to methods, filling in method headers with parameters, and writing method calls. The content is aimed at enhancing understanding of method structure and usage in code.

Uploaded by

musunuru.nikhil
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Writing Methods Worksheet Guide

The document is a worksheet focused on writing methods in programming. It includes exercises for identifying code segments related to methods, filling in method headers with parameters, and writing method calls. The content is aimed at enhancing understanding of method structure and usage in code.

Uploaded by

musunuru.nikhil
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Writing Methods​ ​

Worksheet

Matching: Identify the code segments indicated in bold as:

a)​ Method header


b)​ Method call
c)​ Arguments (actual parameters)
d)​ Formal parameters
e)​ Object name
f)​ Method name
g)​ Error

1.​[Link](2, 8);

2.​[Link]("Hello",5);

3.​ public void welcome(String back)

4.​ [Link]("Hello",5);

5.​ public void doStuff(String num)

6.​ [Link](27.5);

7.​Helper help = new Helper();


int n1 = 12;
int n2 = 5;
[Link](int n1, int n2);

​ ​ ​ ​ ​ ​
8.​Fill in the method header below with two formal parameters called n1 and n2. The data passed in will
be used as whole numbers.

public void addNums( , )

9.​Fill in the method header with two parameters that will be used for a person’s name and a dollar amount
(in that order). You may create your own variable names.

public void mystery( , )

10.​ Fill in the method header that corresponds to the following method call. There are 7 blanks, you may
have to scroll to see them all. You can create the variable names.​ ​
[Link]("Bob", 45, 12.99);
Writing Methods​ ​
Worksheet

public void ( , , )

11.​ Consider the following method header in a class called Farm:


​ public void chicken(String name, double weight)

The chicken's name is "Charlie" and weighs 6.7 pounds. Below is the program segment in the main
method. Write the method call to activate the chicken method.

​ Farm animal = new Farm();



. ( , );

You might also like