面向对象的三大特征

面向对象的三大特征

面向对象的三大特征:封装,继承,多态

封装性在java当中体现:

1.方法就是一种封装

2.关键字private也是一种封装

封装就是将一些细节信息隐藏起来,对外界不可见.

1
2
3
4
5
6
7
8
9
10
public class Main4 {
public static void main(String[] args) {
Phone one = new Phone();
one.brand = "苹果";
one.price = 8388.0;
one.color = "黑色";

one.printAll();//封装性,不用了解方法是怎么实现显示成员变量的,只需要知道怎么调用就行了.
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
public class Phone {
String brand;//产品
double price;//价格
String color;//颜色

public void printAll()
{
System.out.println(brand);
System.out.println(price);
System.out.println(color);
}

}