课程: Java Object-Oriented Programming
今天就学习课程吧!
今天就开通帐号,24,600 门业界名师课程任您挑!
Solution: Reduce complexity with polymorphism - Java教程
课程: Java Object-Oriented Programming
Solution: Reduce complexity with polymorphism
(upbeat music) - [Instructor] To start off we'll create a contact class to represent a contact we might add in our phone. The contact we'll have name, phone number, and email address attributes. All three will be strings. We can represent the phone number as a numerical type, but then we'd have to use a fairly large number. For simplicity we use a string. A given contact could also have a bunch of different phone numbers and email addresses so we could make these lists. But in this example, we'll just say a contact can have one phone number and one email address. For this challenge, we want to be able to create our contacts with different sets of inputs. Sometimes, we'll have access to just a name and a phone number, other times, a name and an email and sometimes all the data. To do this, we'll need to implement compile time polymorphism and overload our constructor. We'll create one constructor that sets up all…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。
内容
-
-
-
-
-
-
(已锁定)
What is polymorphism?1 分钟 22 秒
-
(已锁定)
Writing reusable algorithms with runtime polymorphism4 分钟 47 秒
-
(已锁定)
Exploring different forms in a single object4 分钟 6 秒
-
(已锁定)
Accessing specific object forms with instanceof4 分钟 23 秒
-
(已锁定)
Writing flexible code with compile-time polymorphism4 分钟 38 秒
-
(已锁定)
Exploring how built-in Java classes use polymorphism3 分钟 39 秒
-
(已锁定)
Challenge: Reduce complexity with polymorphism48 秒
-
(已锁定)
Solution: Reduce complexity with polymorphism6 分钟 57 秒
-
(已锁定)
-
-