Đang chuẩn bị liên kết để tải về tài liệu:
Lecture Java methods: Object-oriented programming and data structures (2nd AP edition): Chapter 9 - Maria Litvin, Gary Litvin

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

Chapter 9 - Implementing classes and using objects. This is a long and technical chapter: it deals with several important Java concepts and syntax details. These objectives are within the AP Java Subset for the A-level exam. Some of the details related to classes and methods are left out. Java is a big language. | Implementing Classes and Using Objects Chapter chapter9 = new Chapter(9); Copyright © 2011 by Maria Litvin, Gary Litvin, and Skylight Publishing. All rights reserved. Java Methods Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin 2nd AP edition with GridWorld 9- This is a long and technical chapter: it deals with several important Java concepts and syntax details. Objectives: Review public and private fields and methods Learn the syntax for defining constructors and creating objects Learn the syntax for defining and calling methods Learn how parameters are passed to constructors and methods and how to return values from methods Learn about static and instance fields and methods 9- These objectives are within the AP Java Subset for the A-level exam. Some of the details related to classes and methods are left out. Java is a big language. Class’s Client Any class that uses class X is called a client of X Class X private fields private methods public . | Implementing Classes and Using Objects Chapter chapter9 = new Chapter(9); Copyright © 2011 by Maria Litvin, Gary Litvin, and Skylight Publishing. All rights reserved. Java Methods Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin 2nd AP edition with GridWorld 9- This is a long and technical chapter: it deals with several important Java concepts and syntax details. Objectives: Review public and private fields and methods Learn the syntax for defining constructors and creating objects Learn the syntax for defining and calling methods Learn how parameters are passed to constructors and methods and how to return values from methods Learn about static and instance fields and methods 9- These objectives are within the AP Java Subset for the A-level exam. Some of the details related to classes and methods are left out. Java is a big language. Class’s Client Any class that uses class X is called a client of X Class X private fields private methods public methods public constructor(s) Class Y A client of X Constructs objects of X and/or calls X’s methods 9- The same programmer can develop a class and its client(s). Public vs. Private Public constructors and methods of a class constitute its interface with classes that use it — its clients. All fields are usually declared private — they are hidden from clients. Static constants occasionally can be public. “Helper” methods that are needed only inside the class are declared private. 9- Static public constants (for example, Math.PI or Color.BLUE) do not violate the spirit of encapsulation because they are specifically intended to be used by the class’s clients. Public vs. Private (cont’d) A private field is accessible anywhere within the class’s source code. Any object can access and modify a private field of another object of the same class. public class Fraction { private int num, denom; . public multiply (Fraction other) { int newNum = num * other.num; . 9- num is private to