Chapter 4 (part 2).

Slides:



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

Copyright © 2002 Pearson Education, Inc. Slide 1.
Chapter 10 Pointers and Dynamic Arrays. Copyright © 2006 Pearson Addison-Wesley. All rights reserved Learning Objectives Pointers Pointer variables.
This is Java Jeopardy Writing Methods…chapter 4…
Chapter 6 Advanced Function Features Pass by Value Pass by Reference Const parameters Overloaded functions.
Review What is a virtual function? What can be achieved with virtual functions? How to define a pure virtual function? What is an abstract class? Can a.
1 Composition A whole-part relationship (e.g. Dog-Tail) Whole and part objects have same lifetime –Whole creates instance of part in its constructor In.
Road Map Introduction to object oriented programming. Classes
Chapter 14: Overloading and Templates
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
More on Operator Overloading CS-2303, C-Term More on Operator Overloading CS-2303 System Programming Concepts (Slides include materials from The.
Chapter 13: Overloading.
Fall 2005CSE 115/503 Introduction to Computer Science I1 Composition details Recall, composition involves 3 things: –Declaration of instance variable of.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 14: Overloading and Templates.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 15: Overloading and Templates.
1 Chapter 3 and 6– Classes, Objects and Methods Object-Oriented Programming Concepts – Read it from Java TutorialJava Tutorial Definition: A class is a.
Lecture # 8 Constructors Overloading. Topics We will discuss the following main topics: – Static Class Members – Overloaded Methods – Overloaded Constructors.
CS212: Object Oriented Analysis and Design Lecture 7: Arrays, Pointers and Dynamic Memory Allocation.
Chapter 10 Classes and Objects: A Deeper Look Visual C# 2010 for Programmers © by Pearson Education, Inc. All Rights Reserved.
ECE122 Feb. 22, Any question on Vehicle sample code?
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
 Classes in c++ Presentation Topic  A collection of objects with same properties and functions is known as class. A class is used to define the characteristics.
More C++ Features True object initialisation
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 15: Overloading and Templates.
Chapter 8: Advanced Method Concepts. Understanding Parameter Types Mandatory parameter – An argument for it is required in every method call Four types.
From C++ to C# Part 5. Enums Similar to C++ Similar to C++ Read up section 1.10 of Spec. Read up section 1.10 of Spec.
Chapter 6 - More About Problem Domain Classes1 Chapter 6 More About Problem Domain Classes.
Week 12 Methods for passing actual parameters to formal parameters.
Classes - Intermediate
5.1 Basics of defining and using classes A review of class and object definitions A class is a template or blueprint for an object A class defines.
Classes: A Deeper Look D & D Chapter 9 Instructor - Andrew S. O’Fallon CptS 122 Washington State University.
CSCI/CMPE 4341 Topic: Programming in Python Chapter 7: Introduction to Object- Oriented Programming in Python – Exercises Xiang Lian The University of.
Objects as a programming concept
Passing Objects to Methods
Chapter 13: Overloading and Templates
Haidong Xue Summer 2011, at GSU
More About Objects and Methods
Chapter 5 Functions DDC 2133 Programming II.
Constructor & Destructor
Class: Special Topics Copy Constructors Static members Friends this
Chapter 15: Overloading and Templates
More about OOP and ADTs Classes
Using local variable without initialization is an error.
C Passing arrays to a Function
Introduction to Classes
Corresponds with Chapter 7
Chapter 6 Methods: A Deeper Look
Chapter 9 Classes: A Deeper Look, Part 1
Inheritance, Polymorphism, and Interfaces. Oh My
Variables and Their scope
More about OOP and ADTs Classes
Learning Objectives Classes Constructors Principles of OOP
Indirection.
Defining Classes and Methods
The Destructor and the Assignment Operator
Strings and Pointer Arrays
Which best describes the relationship between classes and objects?
9-10 Classes: A Deeper Look.
Chapter 6 Objects and Classes
1.4 ทบทวน JAVA OO Programming Concepts Declaring and Creating Objects
Classes CSC 265 (Blum).
Unit-1 Introduction to Java
Chapter (3) - Procedures
Constructors & Destructors
9-10 Classes: A Deeper Look.
Creating and Using Classes
SPL – PS3 C++ Classes.
Chapter 4 Test Review First day
Presentation transcript:

Chapter 4 (part 2)

Topic Outline Method overloading Usage of this reference Passing parameter: Object as parameter Object as method type Array of objects Composite objects

Method Overloading

Method Overloading

Method Overloading

Method Overloading Example program that has 4 methods which receive different types of parameter list. All methods are named as overloadDemo.

Method Overloading Try It!

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

this also used to invoke another constructor

Passing Parameter

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

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.

Objects As Parameter

Example