Đang chuẩn bị liên kết để tải về tài liệu:
Using Classes and Objects

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

Once an object has been instantiated, we can use the dot operator to invoke its methods title.length(); Note: A method may return a value or not Example: String s = new String(“Hello"); int count = s.length(); System.out.println("Length of s is " + count); | Chapter 2 Using Classes and Objects Outline Creating object Class libraries and Packages The String class The Scanner class The Random class The Math class Formatting output Wrapper classes - Autoboxing Writing method Slide Creating object Way 1: String title = new String("Java Software Solutions"); Way 2: String title; // this is called a reference variable title = new String("Java Software Solutions"); ClassName object_name = new ClassName(.); ClassName object_name; object_name = new ClassName(.); 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 Slide Invoking method Once an object has been instantiated, we can use the dot operator to invoke its methods title.length(); Note: A method may return a value or not Example: String s = new String(“Hello"); int count = s.length(); System.out.println("Length of s is " + count); Slide References A . | Chapter 2 Using Classes and Objects Outline Creating object Class libraries and Packages The String class The Scanner class The Random class The Math class Formatting output Wrapper classes - Autoboxing Writing method Slide Creating object Way 1: String title = new String("Java Software Solutions"); Way 2: String title; // this is called a reference variable title = new String("Java Software Solutions"); ClassName object_name = new ClassName(.); ClassName object_name; object_name = new ClassName(.); 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 Slide Invoking method Once an object has been instantiated, we can use the dot operator to invoke its methods title.length(); Note: A method may return a value or not Example: String s = new String(“Hello"); int count = s.length(); System.out.println("Length of s is " + count); Slide References A primitive variable contains the value itself An object reference contains the address of the object An object reference can be thought of as a pointer to the location of the object "Java" name1 num1 38 int num1 = 38; String name1 = "Java"; Slide Assignment revisited For primitive types, assignment copies the value and stores it in a variable Example: num1 38 num2 96 Before: num2 = num1; num1 38 num2 38 After: int num1=38, num2=96; num2 = num1; Slide Revisited xem xét lại Assignment revisited (cont.) For object references, assignment copies the address Example: name2 = name1; name1 name2 Before: "Java" "C/C++" name1 name2 After: "Java" String name1="Java", name2="C/C++"; name2 = name1; Slide Aliases Two or more references that refer to the same object are called aliases of each other That creates an interesting situation: one object can be accessed using multiple reference variables Aliases can be useful, but should be managed carefully Changing an object through one reference .

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.