面向对象3大特性之封装.docVIP

  • 0
  • 0
  • 约3.89千字
  • 约 4页
  • 2017-08-19 发布于北京
  • 举报
java学习已经到了最核心的章节,面向对象的三大特性:封装,继承和多态。接下来会写多篇博文(数目不定,请关注近期博客吧!午饭们!)来总结这里面的每一个细节,小可很希望每一篇文章的阐述会给你带来一点启发,小可也是在学习的道路上摸索,也希望各位大牛给点指导性的建议。 还是先从下面的代码说起吧! package com.ivantian.CoreFengZhuang; import static java.lang.System.*; // class Wife{ private String name; private double hight; private double weight; //构造函数 Wife(String name,double hight,double weight){ this.name = name; this.hight = hight; this.weight = weight; } public String getName() { return name; } public void setName(String name) { this.name = name; } public double getHight() { return hight; } public void setHight(double hight) { this.hight = hight; } public double getWeight() { return weight; } public void setWeight(double weight) { this.weight = weight; } // public void washClothes(){ out.println(this.getName()+ 给我洗衣服。); } // public void cookDinner(){ out.println(this.getName()+ 给我烧饭吃。); } // public boolean beautiful(){ if((this.hight=180.00 this.hight=150.00)(this.weight=180.00 this.weight=100.00)){ out.println(this.getName()+ is My favorite!); return true; }else{ out.println(this.getName()+ 不是我的菜。); return false; } } } public class FindWife { public static void main(String[] args) { //实例化三个奇女子 Wife fengjie = new Wife(凤姐,140.00,163.00); Wife furong = new Wife(芙蓉姐姐,170.00,172.00); Wife xiaoyueyue = new Wife(小月月,200.00,156.00); //凤姐能不能为你洗衣服? if(fengjie.beautiful()){ fengjie.washClothes(); fengjie.cookDinner(); } out.println(=====================); if(xiaoyueyue.beautiful()){ xiaoyueyue.washClothes(); xiaoyueyue.cookDinner(); } //让小月月改变 xiaoyueyue.setHight(160.00);//小月月增高成功 xiaoyueyue.setWeight(160.00);//小月月成功减肥 //小月月也成美女了 out.println(=====================); if(xiaoyueyue.beautiful()){ xiaoyueyue.washClothes();

文档评论(0)

1亿VIP精品文档

相关文档