java练习册(010)––类.docVIP

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
  4. 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
  5. 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们
  6. 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
  7. 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
——JAVA篇 JAVA语言中的类(2) 一、练习目标: 类的声明以及属性,方法的定义。 类,属性,方法的访问权限。 final的使用。 this的使用。 Static 的使用。 二、练习时间与作业要求: 本次练习一共需要180分钟。翻译练习写在JAVA笔记本上,书面作业写在JAVA家庭作业本上。 后面的书面作业不包括在这个时间范围内。 三、翻译练习: 将下面要求翻译的内容,写在记事本上 Class access In Java, the access specifiers can also be used to determine which classes within a library will be available to the users of that library. If you want a class to be available to a client programmer, you use the public keyword on the entire class definition. This controls whether the client programmer can even create an object of the class. To control the access of a class, the specifier must appear before the keyword class. Thus you can say: public class Widget { Now if the name of your library is mylib, any client programmer can access Widget by saying import mylib.Widget; or import mylib.*; However, there’s an extra set of constraints: There can be only one public class per compilation unit (file). The idea is that each compilation unit has a single public interface represented by that public class. It can have as many supporting package-access classes as you want. If you have more than one public class inside a compilation unit, the compiler will give you an error message. The name of the public class must exactly match the name of the file containing the compilation unit, including capitalization. So for Widget, the name of the file must be Widget.java, not widget.java or WIDGET.java. Again, you’ll get a compile-time error if they don’t agree. It is possible, though not typical, to have a compilation unit with no public class at all. In this case, you can name the file whatever you like. 四、上机练习: 1. 将圆周率定义为常量,编写一个求圆面积的方法,调用此方法来求圆的面积。 2. 定义一个学生类,包含三个属性(学号,姓名,成绩)均为私有的,分别给这三个属性定义两个方法,一个设置它的值,另一个获得它的值。然后在一个测试类里试着调用。 3、创建一个汽车类(Car),为其定义两个属性:颜色和型号,为该类创建两个构造方法: 第一个为无形参的构造方法,利用其中方法将颜色和型号设置为红色、轿车 第二个为带参构造方法,利用构造方法将颜色和型号设置为黑色、轿车,另外为该类创建两个方法,分别用来显示颜色和型号。 4.修改上次写的人类,使它有多个构造函数,可以用姓名构造一个人,也可以用姓名,性别构造一个人。 练习各种访问权限的访问范围.和static关键字的使用。 五、书面作业: 什么是构造函数?其书写格式是什么?

文档评论(0)

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

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

1亿VIP精品文档

相关文档