课程: Java Object-Oriented Programming
今天就学习课程吧!
今天就开通帐号,24,600 门业界名师课程任您挑!
Implementing encapsulation with access modifiers - Java教程
课程: Java Object-Oriented Programming
Implementing encapsulation with access modifiers
- [Narrator] With encapsulation we want to make data hidden from other classes so they cannot use it directly. However, we still want it to be accessible indirectly through a clear pathway. in Java, one way we can achieve encapsulation for our attributes is to declare each attribute as private then write public methods to get and set the value of each attribute. With this, other classes will still be able to access the hidden data, but they can only do so through a public method of a given class. Let's continue working with our tree class and create three public methods that retrieve each attribute value. To make the first, we'll write public, double for the return type and we'll have it be getHeightFt and this will retrieve the height feet attribute. We'll also create a method for the trunk diameter then as we type it in, you'll notice our IDE comes up with some code completion. And it fills in the code for us…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。
内容
-
-
-
-
(已锁定)
What is encapsulation?2 分钟 16 秒
-
(已锁定)
Discovering access modifiers2 分钟 35 秒
-
(已锁定)
Implementing encapsulation with access modifiers4 分钟 20 秒
-
(已锁定)
Exploring encapsulation in Java string class3 分钟 37 秒
-
(已锁定)
Challenge: Banking application1 分钟 14 秒
-
(已锁定)
Solution: Banking application4 分钟 29 秒
-
(已锁定)
-
-
-
-