Lecture Java methods: Object-oriented programming and data structures (3rd AP edition): Chapter 11 - Maria Litvin, Gary Litvin

Chapter 11 - Class hierarchies and interfaces. In this chapter, the learning objectives are: Understand class hierarchies and polymorphism, learn about abstract classes, learn the syntax for calling superclass’s constructors and methods, understand interfaces. | Copyright © 2015 by Maria Litvin, Gary Litvin, and Skylight Publishing. All rights reserved. Java Methods Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin 3rd AP edition Chapter11 size capacity 11- This chapter also introduces the List interface. Objectives: Learn about the class, its constructors and methods Review some of the ArrayList pitfalls Practice with using ArrayList in client classes and in subclasses 11- ArrayList is part of the Java Collections Framework (Chapter 20), but other collections are not tested on AP exams. Implements a list using an array Implements interface (discussed in Chapter 12) 11- implements . Another implementation of List is (Chapter 20). cont’d Can only hold objects (of a specified type), not elements of primitive data types. Keeps track of the list | Copyright © 2015 by Maria Litvin, Gary Litvin, and Skylight Publishing. All rights reserved. Java Methods Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin 3rd AP edition Chapter11 size capacity 11- This chapter also introduces the List interface. Objectives: Learn about the class, its constructors and methods Review some of the ArrayList pitfalls Practice with using ArrayList in client classes and in subclasses 11- ArrayList is part of the Java Collections Framework (Chapter 20), but other collections are not tested on AP exams. Implements a list using an array Implements interface (discussed in Chapter 12) 11- implements . Another implementation of List is (Chapter 20). cont’d Can only hold objects (of a specified type), not elements of primitive data types. Keeps track of the list capacity (the length of the allocated array) and list size (the number of elements currently in the list) "Cat" "Hat" "Bat" capacity size . 11- As opposed to a regular array, ArrayList’s methods check that an index is from 0 to size() - 1, not just from 0 to capacity - 1. ArrayList Generics Starting with Java 5, ArrayList and other collection classes hold objects of a specified data type. The elements’ data type is shown in angle brackets and becomes part of the List and ArrayList type. For example: ArrayList words = new ArrayList(); List nums = new ArrayList(); 11- We would prefer to call them “type-specific collections” rather than “generic collections.” ArrayList Constructors ArrayList ( ) ArrayList (int capacity) Creates an empty ArrayList of default capacity (ten) Java docs use the letter E as the type parameter for elements in generic collections Creates an empty ArrayList of the specified capacity 11- If you know

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã 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.