




已阅读5页,还剩4页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1class Anthropoid /类人猿private int n=100;void crySpeak(String s)System.out.println(s);class People extends Anthropoidvoid computer(int a,int b)int c=a*b;System.out.println(c);void crySpeak(String s)System.out.println(*+s+*);public class Monkeypublic static void main(String args)Anthropoid monkey=new People(); /monkey是People对象的上转型对象/puter(10,10); /非法monkey.crySpeak(我喜欢这个运动);People people=(People)monkey; /把上转型对象强制转化为子类的对象puter(10,10);2class ManyArea public double area(double radius) return Math.PI*radius*radius; public double area(double len,double width) return len*width; public double area(int len,int width) return len*width; public double area(double len,double width,double height) return len*width*height; public class OverLoad public static void main(String args) ManyArea ob=new ManyArea(); System.out.println(半径为3.0的圆的面积:+ob.area(3.0); System.out.println(长2.0、宽3.0的面积:+ob.area(2.0,3.0); System.out.println(长2、宽3的面积:+ob.area(2,3); System.out.println(立方体的面积:+ob.area(2.0,3.0,4.0); 3class Animal public void shout() class Dog extends Animal public void newDog()System.out.println(Dog的新特性);public void shout() System.out.println(汪);class Cat extends Animal public void shout() System.out.println(喵);class Testpublic void animalshout(Animal a) a.shout(); public class PolyExpublic static void main(String args)Animal d=new Dog();/(1)Dog d1= (Dog)d;/(3)父类对象强制转换成子类对象d1.newDog();/d.newDog(); d.shout();Test t=new Test();t.animalshout(d);/(2)t.animalshout(d1);4class ArrayEx public int subarray(int a,int start,int end) int subarr = new intend-start; for(int i=0,j=start;jend;i+,j+) subarri = aj; return subarr; public class Test public static void main(String args) ArrayEx arrex = new ArrayEx(); int arr = new int10; for(int i = 0;iarr.length;i+) arri = i+10; int sub = arrex.subarray(arr,2,6); for(int temp:sub) System.out.println(temp); 5class Box int length; int width; int height; void set(int len,int wid,int hei) length = len; width = wid; height = hei; class ShowBox void show(Box b) System.out.println(b.length+ +b.width+ +b.height); class TestTwo public static void main(String args) Box a = new Box(); a.set(3,4,5); ShowBox sbox = new ShowBox(); sbox.show(a); 6.class One int a = 5; void showB() int a = 3; int b = this.a; System.out.println(b = +b); public class ThisOne public static void main(String args) One test = new One(); test.showB(); 7.class Mystatic private int x=3; public static void showx() System.out.println(x=+x); public static int add(int m) return m+x; class UseMystatic public static void main(String args) Mystatic.showx(); System.out.println(add=+Mystatic.add(2); 8.class Point int x; int y; Point() x=0; y=0; /this(1,1); Point(int a,int b) x=a; y=b; void show() System.out.println(x=+x+ y=+y); public class UsePoint public static void main(String args) Point p = new Point(); p.show(); 9. class Point private int x,y;Point() x=1; y=3; void showPoint(Point t) System.out.println(x=+t.x+ y=+t.y); void seeit() showPoint(this); public class UsePointThispublic static void main(String args)Point p=new Point();p.seeit();10class Point static int x=2; int y=0; public class UseStatic public static void main(String args) System.out.println(利用类调用静态变量); System.out.println(x=+Point.x); /System.out.println(y=+Point.y); Point p1=new Point(); System.out.println(利用对象调用); System.out.println(x=+p1.x); System.out.println(y=+p1.y); Point p2=new
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 金融领域风险模拟的量子计算技术2025年应用突破研究报告
- 教育游戏化:2025年伦理教育改革实践报告
- 报废轿车补偿方案(3篇)
- 新能源与环保:2025年新能源汽车充电桩安全性能提升与智能化运维策略分析报告
- 社区园林命名方案(3篇)
- 卧房装修改造方案(3篇)
- 管理培训生述职报告
- 能源与资源行业储能技术市场深度研究报告
- 卫浴行业会议管理方案(3篇)
- 口腔门诊集中采购方案(3篇)
- 电力设备安装人员安全教育培训手册
- 怀特海《教育的目的》读书分享
- 教育金保险理念
- 普通货物道路运输安全生产管理制度
- 2025年校长职级考试题及答案
- 2025年广西继续教育公需科目考试试题和答案
- 健康体检服务投标方案投标文件(技术方案)
- 医院行风建设培训
- 物业服务合同培训课件
- 腰痛的预防和治疗讲解讲课件
- DZ∕T 0289-2015 区域生态地球化学评价规范(正式版)
评论
0/150
提交评论