hi people, just new to this site searching for a bit of help in defining the concepts of actual and formal parameters when declaring and calling methods in program.
Now ive only started studying java so i honestly dont really understand what it means for a program to 'call' a method. so it would be good if someone could shed some light on that too.
the piece of code that im trying to analyse here is the following:
1 public class Scope { 2 public static void test(int num) { 3 if (num > 10) { 4 int half = num / 2; 5 System.out.println(“Half num = “ + half); 6 } else { 7 System.out.println(num); 8 } 9 } 10 public static void main(String[] args) 11 { 12 int x = 5; 13 test(x); 14 } 15 }
as i say im trying to determine the actual and formal parameters used in the definition and call of the method, 'test'
any help would be appreciated, thanks very much
what i have at the minute (i have to answer this by reasoning it out)is the following-
'When declaring your method at the top of a piece of code the header determines if a method returns any result or takes any parameters on. A method should either return a value or no value (known as an action method) and it can take 0 or more parameters.
Formal parameters are variables that can be declared in the parameter list of a subprogram specification.'
to be honest im taking a lot of that from the notes my lecturer provided (not directly) so im not so sure what that last bit means.
again any help will be greatly appreciated
cheers