Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 4 (part 2).

Similar presentations


Presentation on theme: "Chapter 4 (part 2)."— Presentation transcript:

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.

7

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

10

11

12 this also used to invoke another constructor

13

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

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37


Download ppt "Chapter 4 (part 2)."

Similar presentations


Ads by Google