对象的应用编程.docxVIP

  1. 1、本文档共9页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
  5. 5、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
  6. 6、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们
  7. 7、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
  8. 8、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
对象的应用编程

对象的应用编程实验目的:掌握对象的生成机制2.了解构造函数的作用实验内容对象创建和使用。使用关联类进行属性的定义。访问控制修饰符的作用。掌握静态属性、方法和初始化器的特点。包的应用实验步骤写一个名为Rectangle的类表示矩形。其属性包括宽width、高height和颜色color,width和height都是double型的,而color则是String类型的。要求该类提供计算面积的方法getArea()方法,以及修改width和height的值及获得width和height当前值的方法。要求:使用构造函数完成各属性的初始赋值使用getter和sr的形式完成属性的访问及修改public class Rectangle {private double width;private double height;private String color; public Rectangle(double width, double height, String color) {this.width = width;this.height = height;this.color = color;}public double getWidth() {return width;}public void setWidth(double width) {this.width = width;}public double getHeight() {return height;}public void setHeight(double height) {this.height = height;}public double getArea(){double area;return area=width*height;}public static void main(String[] args) {Rectangle a=new Rectangle(2.0,3.0,red);System.out.println(a.getArea());}}一个Fan有自己的品牌和型号,其功能有start,stop,speed,start和stop可以改变Fan的状态status(on/off),speed可以调整Fan的速度(档级在0、1、2、3),请分析并提供Fan类的定义。并编写程序对其进行测试。Public class Fan {private String band; private String type;private String status ;private int speed;public Fan(String band,String type,String status,int speed){this.band=band;this.type=type;this.status=status;this.speed=speed;}public String start(){return status;}public String stop(){return status;}public void speed(int a){this.speed=a;}public static void main(String[]args){Fan t=new Fan(ss,dd,off,1);System.out.printf(%s,%s,%b,%d,t.band,t.type,t.status,t.speed); }}解释下面的程序运行结果输出为什么是null public class My { String s; public void My(){ s = Constructor; } public void go() { System.out.println(s); } public static void main(String args[]) { My m = new My(); m.go(); } }调用者没有传递值2.写出程序运行结果class StaticDemo { static int x; int y; static{ x=10;} public static int getX() { return x; } public static void setX(int newX) { x = newX; } public int getY() { return y; } public void setY(int newY) { y = newY; } public static void main(String[] args) { System.out.println(静态变量x=+StaticDemo.getX()); System.out

文档评论(0)

yan698698 + 关注
实名认证
文档贡献者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档