Download presentation
Presentation is loading. Please wait.
1
Chapter 4 (part 2)
2
Topic Outline Method overloading Usage of this reference
Passing parameter: Object as parameter Object as method type Array of objects Composite objects
3
Method Overloading
4
Method Overloading
5
Method Overloading
6
Method Overloading Example program that has 4 methods which receive
different types of parameter list. All methods are named as overloadDemo.
8
Method Overloading Try It!
9
The this reference this is a reference variable that refers to the current object. Known as self-referencing pointer To avoid naming conflicts – declare the name of instance variables and local variables are same
12
this also used to invoke another constructor
14
Passing Parameter
15
Passing Parameter The power of method is its ability to work with parameters. When calling a method, arguments need to be provided. When method with parameter is invoked, the value of the arguments is passed to the parameter. Two types of passing parameter: Pass by value Pass by reference
16
Object As Parameter When an object reference is passed into a method, a copy of the reference is actually manipulated by the method. So, the method can change the attributes of the object. Passing object as an argument is actually passing the reference of the object.
17
Objects As Parameter
18
Example
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.