Passing information through Parameters ( our setter methods or mutators) Formal Parameter – parameter in the method. public void SetA(int x){ (int x) is.

Slides:



Advertisements
Similar presentations
Chapter 4 Constructors and Destructors. Objectives Constructors – introduction and features The zero-argument constructor Parameterized constructors Creating.
Advertisements

M The University Of Michigan Andrew M. Morgan Andrew M Morgan1 EECS Lecture 03 Savitch Ch. 3-4, Misc More on Functions Memory, Activation Records,
1 Classes and Objects in Java Parameter Passing, Delegation, Visibility Control, and Object Cleanup.
Lecture 10 Methods COMP1681 / SE15 Introduction to Programming.
For(int i = 1; i
Picture It Very Basic Game Picture Pepper. Original Game import java.util.Scanner; public class Game { public static void main() { Scanner scan=new Scanner(System.in);
How do Methods Work?. Let’s write a method that adds two integer values together and returns the result.
Chapter 6 Advanced Function Features Pass by Value Pass by Reference Const parameters Overloaded functions.
Understanding Parameter Passing. Parameters are Passed by Value zIt is important to understand how parameter passing works. When you make changes to a.
1 Classes, Encapsulation, Methods and Constructors (Continued) Class definitions Instance data Encapsulation and Java modifiers Method declaration and.
PASSING PARAMETERS 1. 2 Parameter Passing (by Value) Parameters Formal Parameters – parameters listed in the header of the function Variables used within.
Methods. int month; int year class Month Defining Classes A class contains data declarations (static and instance variables) and method declarations (behaviors)
Constructors & An Introduction to Methods. Defining Constructor – Car Example Public class car { String Model; double speed; String colour; { Public Car.
H OW O BJECTS B EHAVE. O VERVIEW Methods use object state Arguments and return types in methods Java passes by value Getters and Setters Encapsulation.
Overloading methods review When is the return statement required? What do the following method headers tell us? public static int max (int a, int b)
CS-212 Classes (cont) Dick Steflik. Member functions Member functions of a class include – getters used to retrieve state data – setters used to set state.
Blue Box Diagram Method contains a block of instructions We pass (give) The method information (expressions) as arguments to use Processing is done in.
Functions Pass by Value Pass by Reference IC 210.
SE-1010 Dr. Mark L. Hornick 1 Defining Your Own Classes Part 3.
Local Variables A local variable is a variable that is declared within a method declaration. Local variables are accessible only from the method in which.
C++ function call by value The call by value method of passing arguments to a function copies the actual value of an argument into the formal parameter.
Functions Pass by Reference Alina Solovyova-Vincent Department of Computer Science & Engineering University of Nevada, Reno Fall 2005.
Chapter 3: Developing Class Methods Object-Oriented Program Development Using Java: A Class-Centered Approach.
CH 8 : Enhancing Classes - Review QUICK REVIEW : A Class defines an entity’s (Object’s) data and the actions or behaviors (Methods) associated with that.
Writing Methods Mrs. C. Furman October 9, Drawing a Square World worldObj = new World(); Turtle turtle1 = new Turtle(100, 100, worldObj); turtle1.forward.
Methods and Parameters Chapter 5 How to split large programs into isolated sections. Focus on one part of the problem – which can be “called” on or “invoked”
Chapter 4 -2 part Writing Classes 5 TH EDITION Lewis & Loftus java Software Solutions Foundations of Program Design © 2007 Pearson Addison-Wesley. All.
Classes. Constructor A constructor is a special method whose purpose is to construct and initialize objects. Constructor name must be the same as the.
Coding Bat: Ends in ly Given a string of even length, return a string made of the middle two chars, so the string "string" yields "ri". The string.
Java Classes Chapter 1. 2 Chapter Contents Objects and Classes Using Methods in a Java Class References and Aliases Arguments and Parameters Defining.
Encapsulation, Inheritance, Composition. Class Methods Can be either void or return Can have parameters or not Must be static Should be public Know how.
CMSC 150 METHODS AND CLASSES CS 150: Wed 25 Jan 2012.
TOPIC 6 Methods F Introducing Methods F Declaring Methods F Calling Methods F Passing Parameters F Pass by Value F Overloading Methods F Method Abstraction.
1 Week 8 l Methods l Parameter passing Methods. 2 Using Methods l Methods are actions that an object can perform. l To use a method you invoke or call.
Creating and Using Class Methods. Definition Class Object.
CSCI 62 Data Structures Dr. Joshua Stough December 2, 2008.
CSC 142 F 1 CSC 142 References and Primitives. CSC 142 F 2 Review: references and primitives  Reference: the name of an object. The type of the object.
Classes - Intermediate
Methods.
CPSC 233 Tutorial 5 February 9 th /10 th, Java Classes Each Java class contains a set of instance variables and methods Instance Variables: Type.
Class Everything in Java is in a class. The class has a constructor that creates the object. If you do not supply a constructor Java will create a default.
Review – Primitive Data What is primitive data? What are 3 examples of primitive data types? How is a piece of primitive data different from an object?
Staples are our staple Building upon our solution.
AKA the birth, life, and death of variables.
Chapter 10: Void Functions
Chapter 5 Functions DDC 2133 Programming II.
Methods The real power of an object-oriented programming language takes place when you start to manipulate objects. A method defines an action that allows.
An Introduction to Java – Part II
Chapter 4 (part 2).
The this Reference The this reference allows an object to refer to itself That is, the this reference, used inside a method, refers to the object through.
Variables and Their scope
Encapsulation and Constructors
Classes, Encapsulation, Methods and Constructors (Continued)
Introduction to Object-Oriented Programming with Java--Wu
Array and Method.
Java Lesson 36 Mr. Kalmes.
Parameter Passing in Java
Method Overloading in JAVA
Understanding Parameter Passing
CS2011 Introduction to Programming I Methods (II)
JAVA Constructors.
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
Class Everything if Java is in a class. The class has a constructor that creates the object. public class ClassName private Field data (instance variables)
Methods Again Parameter Passage
class PrintOnetoTen { public static void main(String args[]) {
Class: Special Topics Overloading (methods) Copy Constructors
Unit-1 Introduction to Java
Corresponds with Chapter 5
ITE “A” GROUP 2 ENCAPSULATION.
C Parameter Passing.
Presentation transcript:

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.

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

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.