Chapter 9: Functions and Methods


OVERVIEW

The main goal of this chapter is to explain how arguments are passed to functions in C++ and Java. While C++ gives us three different options—pass by value, pass by pointer, and pass by reference—Java uses only pass by value.

But for class type arguments, pass by value in C++ does not mean the same thing as pass by value in Java. An important goal of this chapter is to explain the distinction between the two. To differentiate between the two "pass by value" modes, we say that in Java arguments are passed by value of object reference.

The other important topics discussed in this chapter include function overloading, overload resolution algorithms, function inlining in C++, const parameters in C++, final parameters in Java, and so on.

Recall from our earlier mention that when a function is defined as a member of a class, it is usually called a method, especially if polymorphism can be used with respect to that function. Strictly speaking, only virtual member functions in C++ should be called methods because only these functions exhibit polymorphic behavior. (Virtual member functions are discussed in Chapter 15.) In Java all functions are methods because functions cannot be defined outside the encapsulation provided by a class and because polymorphism works for all member functions.

In this chapter, we will use the term function generically, particularly in the context of C++. Whatever we say about a function in C++ will also apply to methods in C++. For Java, on the other hand, we will frequently use the term method when referring to functions.




Programming With Objects[c] A Comparative Presentation of Object-Oriented Programming With C++ and Java
Programming with Objects: A Comparative Presentation of Object Oriented Programming with C++ and Java
ISBN: 0471268526
EAN: 2147483647
Year: 2005
Pages: 273
Authors: Avinash Kak

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net