Download presentation
Presentation is loading. Please wait.
Published byJoelle Hosier Modified over 9 years ago
1
Passing information through Parameters ( our setter methods or mutators) Formal Parameter – parameter in the method. public void SetA(int x){ (int x) is the formal parameter Actual Parameter – parameter when you invoke (call) the method and you actually pass the data to the method. myObject.setA(25); 25 is the actual data passed to the setA(int) method.
2
public class MyClass { int a; int b; public MyClass(){ a = 0; b = 0; } public void setA(int x) { a = x; x = 25 a = 25 } public void setB(int y) { b = y; y = 30, b = 30 } In my Main Method: public static void main(String[]args) { Create object from the class. MyClass myObject = new MyClass(); myObject.setA(25); Do I have a setA(int) method? 25 gets passed through the actual parameter to the formal parameter. myObject.setB(30); Do I have a setB(int) method? 30 gets passed through the actual parameter to the formal parameter. Actual Parameter Formal Parameter
3
Argument Passing Argument is the value passed to the parameter. Java uses a pass by value for its argument scheme. Java passes a copy of the argument’s value to the parameter.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.