TAILIEUCHUNG - Lecture An introduction to Object-Oriented Programming with Java - Chapter 4: Defining your own classes

Chapter 4 - Defining your own classes. Learning how to define your own classes is the first step toward mastering the skills necessary in building large programs. In this chapter we will learn how to define instantiable classes and different types of methods included in the instantiable classes. A class is instantiable if we can create instances of the class. The DecimalFormat, GregorianCalendar, and String classes are all instantiable classes while the Math class is not. | Chapter Four Defining Your Own Classes Chapter 4 Objectives After you have read and studied this chapter, you should be able to Define an instantiable class with multiple methods and constructors. Differentiate the local and instance variables. Define and use value-returning methods. Distinguish private and public methods. Distinguish private and public data members. ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 4 Objectives, cont. After you have read and studied this chapter, you should be able to Describe how the arguments are passed to the parameters in method definitions. Describe how the result is returned from a method. Define a reusable class for handling input routines. Define an instantiable main class. ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Defining Instantiable Classes Learning how to define instantiable classes is the first step toward mastering the skills necessary in building large programs. A class is instantiable if we can create instances of the class. The DecimalFormat, GregorianCalendar, and String classes are all instantiable classes, while the Math class is not. ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Defining Instantiable Classes Currency converter example: We need two methods for conversion: fromDollar and toDollar. CurrencyConverter yenConverter; double amountInYen, amountInDollar; yenConverter = new CurrencyConverter( ); . amountInYen = (200); //from dollar to yen amountInDollar = (15000); //from yen to dollar ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Defining Instantiable Classes Since the exchange rate fluctuates, we need a method to set the exchange rate. CurrencyConverter yenConverter; yenConverter = new CurrencyConverter( ); (); ©TheMcGraw-Hill Companies, Inc. Permission required for

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.