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

Chapter 7 - Defining your own classes (part 2). After studying this chapter you will be able to: Describe how objects are returned from methods, describe how the reserved word this is used, define overloaded methods and constructors, define class methods and variables, describe how the arguments are passed to the parameters using the pass-by-value scheme, document classes with javadoc comments, organize classes into a package. | Chapter 7 Defining Your Own Classes Part 2 4th Ed Chapter 7 - ©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 Describe how objects are returned from methods Describe how the reserved word this is used Define overloaded methods and constructors Define class methods and variables Describe how the arguments are passed to the parameters using the pass-by-value scheme Document classes with javadoc comments Organize classes into a package 4th Ed Chapter 7 - ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A class is instantiable if we can create instances of it. For example, the JFrame class is instantiable. A class is noninstantiable if we cannot create its instances. The Math class is one example of noninstantiable classes. The main classes we have been writing are all noninstantiable. We will learn how to define instantiable classes in this lesson. A constructor is a special method that is used to initialize an instance of a class when it is first created. Returning an Object from a Method As we can return a primitive data value from a method, we can return an object from a method also. We return an object from a method, we are actually returning a reference (or an address) of an object. This means we are not returning a copy of an object, but only the reference of this object 4th Ed Chapter 7 - ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. We already know how to return an object from a method, because we have been returning a string from a method and a string is an object (an instance of the String class). However, String objects are treated much like primitive data. We will explore a little deeper into this topic. Sample Object-Returning Method Here's a sample method that returns an object: public Fraction simplify( ) { Fraction simp; int num = getNumberator(); int denom = . | Chapter 7 Defining Your Own Classes Part 2 4th Ed Chapter 7 - ©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 Describe how objects are returned from methods Describe how the reserved word this is used Define overloaded methods and constructors Define class methods and variables Describe how the arguments are passed to the parameters using the pass-by-value scheme Document classes with javadoc comments Organize classes into a package 4th Ed Chapter 7 - ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A class is instantiable if we can create instances of it. For example, the JFrame class is instantiable. A class is noninstantiable if we cannot create its instances. The Math class is one example of noninstantiable classes. The main classes we have been writing are all noninstantiable. We will learn how to define instantiable classes in

crossorigin="anonymous">
Đã 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.