Page 250 - ComputerScience_Class_11
P. 250
15 void perimeter()
16 {
17 p=2*(l+b);
18 System.out.println("Perimeter : "+p);
19 }
20 public static void main(String[] args)
21 {
22 Scanner sc= new Scanner(System.in);
23 geometry_rectangle ob= new geometry_rectangle ();
24 int length, breadth;
25 System.out.println("Enter length of rectangle :");
26 length=sc.nextInt();
27 System.out.println("Enter breadth of rectangle :");
28 breadth=sc.nextInt();
29 ob.accept(length, breadth); // Actual Parameters
30 ob.area();
31 ob.perimeter();
32 }
33 }
The output of the preceding program is as follows:
BlueJ: Terminal Window - Java
Options
Enter length of rectangle :
22
Enter breadth of rectangle :
22
Area : 484
Perimeter : 88
In the above example,
• The length and breadth are the actual parameters which contain two values respectively and the formal parameters
len and bre receive these values in the same order.
Hence, we can now conclude as follows:
• Actual Parameters: The actual values that are passed directly or through the variables to the respective method at
the time of calling the method are called the actual parameters. They are defined in the calling method.
In the above program, the actual parameters are length and breadth which are defined in the calling method.
ob.accept(length,breadth);
• Formal Parameters: The values sent by the calling method are received in the parameters described in the method.
These parameters that receive the values from the caller method are known as the formal parameters. They are
defined in the called method.
In the above program, the formal parameters are len and bre which are defined in the called method.
void accept (int len, int bre);
248 Touchpad Computer Science (Ver. 3.0)-XI

