课程: Java Object-Oriented Programming
今天就学习课程吧!
今天就开通帐号,24,600 门业界名师课程任您挑!
Challenge: Reduce redundant code with inheritance - Java教程
课程: Java Object-Oriented Programming
Challenge: Reduce redundant code with inheritance
(upbeat chiming music) - [Instructor] One common error when using the ArrayList class is sometimes you might try to retrieve an item that's at an invalid index. To avoid this, usually you'll add an if statement in order to check that the index is valid before retrieving the item from the list. However, sometimes those checks can get annoying and another developer might forget to do the check. To provide a foolproof way of accessing items in a given list, we want to create a ModArrayList class with a getUsingMod method that takes in an index and retrieves an item from the list at that index. If the index is invalid, then the implementation should use the mod operation and mod the index based on the length of the list. If the index is negative, then it should be made positive. If you're unfamiliar with mod, mod is similar to division. However, it returns the remainder rather than the quotient when given two numbers of the same…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。
内容
-
-
-
-
-
(已锁定)
What is inheritance?2 分钟 41 秒
-
(已锁定)
Leveraging different types of inheritance2 分钟 49 秒
-
(已锁定)
Using inheritance to reduce code duplication4 分钟 51 秒
-
(已锁定)
Discovering inheritance in foundational Java classes3 分钟 18 秒
-
(已锁定)
Challenge: Reduce redundant code with inheritance1 分钟 51 秒
-
(已锁定)
Solution: Reduce redundant code with inheritance4 分钟 37 秒
-
(已锁定)
-
-
-