第四章 java面向对象程序设计.pptVIP

  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面向对象程序设计

类和对象 类是具有共同特性和行为的事物的抽象,是一种特殊数据类型。在类中包含了数据和与数据有关的操作(方法)。 对象是类的实例。 邮箱: zuoyelcq@126.com 类的成员的访问权限设置 用权限关键字设置类的成员的权限,以此决定是否允许其类外部的代码访问这些成员。 例: private int year, month, day; public today(); import ax.Account ; public class Useraccount{ public static void main( String args[]){ Account myaccount=new Account(); =张三; myaccount.address= 上海市延安西路1号; myaccount.balance=123.40; myaccount.display(); } } package ax; public class Account{ public String name; public String address; public double balance; public void display(){ System.out.println(name:+name); System.out.println(Address:+address); System.out.println(balance:+balance); } } public class Date3 {int year,month,day; Date3(int y,int m,int d) {year=y; month=m; day=d;} Date3() { } public void setdate(int y,int m,int d) {year=y; month=m; day=d;} void today() { System.out.println(The date of today is +year+/+month+/+day);} boolean isleap(int y) { return (y%4==0y%100!=0)|y%400==0 ;} void tomorrow() { int d,m,y; d=day+1;m=month;y=year; if((d28)month==2) {if(!isleap(year)|d29) {d=1;m=m+1;}} else if(d30(month7month%2==0|month7month%2==1)) {d=1;m=m+1;} else if(d31) {d=1;m=m+1; if(m==13){y=y+1;m=1;}} System.out.println(The date of tomorrow is +y+/+m+/+d);} public static void main(String args[]) {Date3 de1,de2; de1=new Date3(1999,3,31); de2=new Date3(); System.out.println(The first object:); if(de1.isleap(de1.year))System.out.println(de1.year+ is a leap year); de1.today(); de1.tomorrow(); System.out.println(The second object:); de2.setdate(2000,2,29); if(de2.isleap(de2.year))System.out.println(de2.year+ is a leap year); de2.today(); de2.tomorrow();} } static static是一个修饰符,表示与类有关系,而不是与类的某一个对象有关系。 类变量(静态成员变量) 类方法(静态方法) class Melon {float weight; static float tota

文档评论(0)

ajgoaw + 关注
文档贡献者

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

1亿VIP精品文档

相关文档