当前位置: 技术问答>java相关
问一道题的意思!
来源: 互联网 发布时间:2015-04-05
本文导语: 1. public class Mycircle { 2. private double radius; 3. private double diameter; 4. 5. public void setRadius(double radius) 6. this.radius = radius; 7. this.diameter= radius * 2; 8. } 10. public double getRadius() { 11. return radius; 12...
1. public class Mycircle {
2. private double radius;
3. private double diameter;
4.
5. public void setRadius(double radius)
6. this.radius = radius;
7. this.diameter= radius * 2;
8. }
10. public double getRadius() {
11. return radius;
12. }
13. }
A. The Mycircle class is fully encapsulated.
B. The diameter of a given MyCircle is guaranteed to be twice its radius.
C. Lines 6 and 7 should be in a synchronized block to ensure encapsulation.
D. The radius of a MyCircle object can be set without affecting its diameter.
这是题目的选择项
正确答案为B!
//问题:
A项说 The Mycircle class is fully encapsulated,那么我如何判断一个没有被封装呢?也就是说判断一个类是否被encapsulated 或者说fully encapsulated的标志是什么,有没有什么规则呢?
2. private double radius;
3. private double diameter;
4.
5. public void setRadius(double radius)
6. this.radius = radius;
7. this.diameter= radius * 2;
8. }
10. public double getRadius() {
11. return radius;
12. }
13. }
A. The Mycircle class is fully encapsulated.
B. The diameter of a given MyCircle is guaranteed to be twice its radius.
C. Lines 6 and 7 should be in a synchronized block to ensure encapsulation.
D. The radius of a MyCircle object can be set without affecting its diameter.
这是题目的选择项
正确答案为B!
//问题:
A项说 The Mycircle class is fully encapsulated,那么我如何判断一个没有被封装呢?也就是说判断一个类是否被encapsulated 或者说fully encapsulated的标志是什么,有没有什么规则呢?
|
A fully encapsulated class has:
1.Private variables
2.Public methods to access the class's properties.
这个类里面少了访问diameter的public方法。
1.Private variables
2.Public methods to access the class's properties.
这个类里面少了访问diameter的public方法。
|
to xiaobi_liang:
我认为是这样的,但是还没有找到准确的定义!
我认为是这样的,但是还没有找到准确的定义!
|
不知道是不是直径是多余的?
程序看上去有些拖沓!
程序看上去有些拖沓!