1、封装(encapsulation)
public class Tree{
private String name;
private String price;
2、继承(succession) :父子关系——extends
3、多态(polymorphic)
-
属性私有:对外提供公有的getter/setter
public String getName() {
return name;
}
public void setName(String mame) {
this.name = name;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price; -
public:公有;private:私有;protected:受保护的
-
例如:树类(封装了它的价格,名字,给其提供了getter/setter,让其共有化)
网友评论