tailieunhanh - Chapter 3 Using Classes and Objects

In object-oriented programming, a class is a construct that is used to create instances of itself – referred to as class instances, class objects, instance objects or simply objects. A class defines constituent members which enable its instances to have state and behavior.[1] Data field members (member variables or instance variables) enable a class instance to maintain state. Other kinds of members, especially methods, enable the behavior of class instances. Classes define the type of their instances.[2]. | Chapter 3 Using Classes and Objects © 2004 Pearson Addison-Wesley. All rights reserved 3- Using Classes and Objects We can create more interesting programs using predefined classes and related objects Chapter 3 focuses on: object creation and object references the String class and its methods the Java standard class library the Random and Math classes formatting output enumerated types wrapper classes graphical components and containers labels and images © 2004 Pearson Addison-Wesley. All rights reserved 3- Outline Creating Objects The String Class Packages Formatting Output Enumerated Types Wrapper Classes Components and Containers Images © 2004 Pearson Addison-Wesley. All rights reserved 3- Creating Objects A variable holds either a primitive type or a reference to an object A class name can be used as a type to declare an object reference variable String title; No object is created with this declaration An object reference variable holds the address of an object The . | Chapter 3 Using Classes and Objects © 2004 Pearson Addison-Wesley. All rights reserved 3- Using Classes and Objects We can create more interesting programs using predefined classes and related objects Chapter 3 focuses on: object creation and object references the String class and its methods the Java standard class library the Random and Math classes formatting output enumerated types wrapper classes graphical components and containers labels and images © 2004 Pearson Addison-Wesley. All rights reserved 3- Outline Creating Objects The String Class Packages Formatting Output Enumerated Types Wrapper Classes Components and Containers Images © 2004 Pearson Addison-Wesley. All rights reserved 3- Creating Objects A variable holds either a primitive type or a reference to an object A class name can be used as a type to declare an object reference variable String title; No object is created with this declaration An object reference variable holds the address of an object The object itself must be created separately © 2004 Pearson Addison-Wesley. All rights reserved 3- Creating Objects Generally, we use the new operator to create an object title = new String ("Java Software Solutions"); This calls the String constructor, which is a special method that sets up the object Creating an object is called instantiation An object is an instance of a particular class © 2004 Pearson Addison-Wesley. All rights reserved 3- Invoking Methods We've seen that once an object has been instantiated, we can use the dot operator to invoke its methods count = () A method may return a value, which can be used in an assignment or expression A method invocation can be thought of as asking an object to perform a service © 2004 Pearson Addison-Wesley. All rights reserved 3- References Note that a primitive variable contains the value itself, but an object variable contains the address of the object An object reference can be thought of as a pointer to the .

TỪ KHÓA LIÊN QUAN
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.