07-CreatingClassMethods - Chapter VII Creating Class...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Chapter VII Creating Class Methods Chapter VII Topics 7.1 Introduction 7.2 The Math Class Revisited 7.3 Modular Programming and User-Created Methods 7.4 User-Declared Parameter Methods 7.5 Void Methods and Return Methods 7.6 Making a Utility Library Class 7.7 The Payroll Case Study 7.8 Program Input with GUI Windows 7.9 Summary Chapter VII Creating Class Methods 305 7.1 Introduction Chapter IV introduced a few Object Oriented Programming (OOP) concepts. In particular, emphasis was placed on encapsulation . You learned that an object is capable of containing both data, often called attributes , and action modules that can process data, called methods . The lion's share of the Chapter IV revolved around using methods of existing classes. You also learned the distinction between calling class methods with the class identifier and object methods with the object identifier. Class methods are normally utility methods that do not access changing data fields. The Math class is a good example of a class where data will not change. There are many methods in the Math class, but only two data fields, PI and E , which do not change. Methods in Math are class methods and must be accessed using the Math class identifier. It is a different story when you have the need to use methods with different sets of data. A new and separate object needs to be constructed for each required variable. A class is a data type, which is capable of only storing information for one single occasion. This presents no problem for a utility class, which does not store any user provided data. However, most classes require variables for many different data storage situations. In the last chapter I showed you the Bank class. That is a good example of a class, which requires multiple objects, one for each customer of the Bank class. In the statement int num; int is the type and num is the variable . Likewise in the statement Bank tom; the class Bank is the type and the object tom is the variable . There is a very important distinction between simple data types like int , double , char , and boolean and complex data types like Math , Random and DecimalFormat . Each one of the simple data types stores only a single value. The variable objects of a class data type, on the other hand, can store many values. Additionally, class data types also contain methods, which can access data. As you saw examples of class methods and object methods, you also learned that methods can have one or more parameters or arguments. Parameters provide information to methods for processing. Additionally, methods fall into two major categories, which are return methods and void methods. Return methods return some requested value, like the tom.getChecking(); method, which returns the checking account balance of the object tom . Void methods do not return any values, but frequently alter object data, like the tom.changeChecking(2000.0); method, which adds $2000.00 to the checking account balance of the tom object....
View Full Document

This note was uploaded on 10/14/2010 for the course APSC AP taught by Professor Kurt during the Spring '98 term at Wooster.

Page1 / 74

07-CreatingClassMethods - Chapter VII Creating Class...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online