tailieunhanh - Lecture An Introduction to Object-Oriented Programming with Java (4/e): Chapter 4 - C. Thomas Wu

Chapter 4 (part 1) - Defining your own classes. After you have read and studied this chapter, you should be able to: Define a class with multiple methods and data members, differentiate the local and instance variables, define and use value-returning methods, distinguish private and public methods, distinguish private and public data members, pass both primitive data and objects to a method. | Chapter 4 Defining Your Own Classes Part 1 4th Ed Chapter 4 - ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Objectives After you have read and studied this chapter, you should be able to Define a class with multiple methods and data members Differentiate the local and instance variables Define and use value-returning methods Distinguish private and public methods Distinguish private and public data members Pass both primitive data and objects to a method 4th Ed Chapter 4 - ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Why Programmer-Defined Classes Using just the String, GregorianCalendar, JFrame and other standard classes will not meet all of our needs. We need to be able to define our own classes customized for our applications. Learning how to define our own classes is the first step toward mastering the skills necessary in building large programs. Classes we define ourselves are called programmer-defined classes. 4th Ed Chapter 4 - ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The sample application programs we have written so far included only one class, the main class of the program. And the main class contained only one method, the main method. When we review the sample programs developed so far, we note two key characteristics: The programs included only one class, the main class of the program. The main class contained only one method, the main method. From this main method, we used objects and classes from the standard packages such as and . Such organization works only for small programs. In order to manage complexity of large programs, it is best to define instantiable classes. First Example: Using the Bicycle Class class BicycleRegistration { public static void main(String[] args) { Bicycle bike1, bike2; String owner1, owner2; bike1 = new Bicycle( ); //Create and assign values to bike1 ("Adam . | Chapter 4 Defining Your Own Classes Part 1 4th Ed Chapter 4 - ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Objectives After you have read and studied this chapter, you should be able to Define a class with multiple methods and data members Differentiate the local and instance variables Define and use value-returning methods Distinguish private and public methods Distinguish private and public data members Pass both primitive data and objects to a method 4th Ed Chapter 4 - ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Why Programmer-Defined Classes Using just the String, GregorianCalendar, JFrame and other standard classes will not meet all of our needs. We need to be able to define our own classes customized for our applications. Learning how to define our own classes is the first step toward mastering the skills necessary in building large programs. Classes we define ourselves are called .

TÀI LIỆU LIÊN QUAN