版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、【必做题】.选择题1 、列选项中哪个是类public class test 的默认构造方法_c_?a. test();b. test(void);c. public test();d. public test(void);e. public void test();2 、给定下列代码的执行结果是_e_?public class a void a() a” );public static void main(string args) new a();a.class ac. 编译错误b. 在第 2 行处抛出异常d. 在第 6 行处抛出异常11e.代码执行后没有输出*3 、给定以下代码:1. pub
2、lic class constover 2. public constover (int x, int y, int z) 3. 4. 下列选项中,哪些可以在consover 类中定义成重载的构造方法_aca. constover ( ) b. int constover ( ) c. constover (int z, int y, byte x) d. object constover (int x, int y, int z) e. void constover (byte x, byte y, byte z) only4 、以下代码的执行结果是_a_ ? /illegal modifi
3、er for parameter i;final is permitted1.2.3.4.5.6.1. q.public class test( public int amethod() static int i=0;i + + ;return i;)(string args)public static void. ma in test test = new test(); test,amethod();1.1 int j = test.amethod();1.5 system.out.printin (j);12 .13 .)a.c.编译失败编译成功,输出“1”b.编译成功,输出“0”d.编
4、译成功,输出“2”5、以下代码的执行结果是c ?l. public class foo 2. . public static void main (stringargs) 3. string s;4. system.out.printin;56. a.代码编译成功,并且打印“s=”b.代码编译成功,并且打印s=null ”c.代码编译失败,因为s为被初始化d.代码编译失败,因为s不可以被引用e.代码编译成功,但是运行时抛出 nullpointerexception6、给定以下代码:12. void start() 13. a a = new a();14. b b = new b();15.
5、a.s(b);16. b = null;17. a = null;18. completed );对于在第14行创建的对象b,系统什么时候会对它进行垃圾回收 _d_?a.在第16行之后b.在第17行之c.在第18行之后(当函数执行完成后) d.无法确定e.垃圾回收器不会回收该对象n.程序分析题1、在指定位置上填写正确的代码:public class circlestaticstatic double pi = 3.14;int radius=100;public static void main(string args)_pi_ );/打印pi_ circlestatic c = new ci
6、rclestatic ();radius _); / 打印 radius2、下面的程序有错误,请修正,并说明原因:public class circlestatic static double pi=3.14;int radius =100;public static void main(string args) ; / 静态方法里不能直接用非静态属性circle c= new circle();class circle static double pi=3.14;int radius;public circle() public circle( int r) radius =r;public
7、 static double getpi() return pi;public void static showarea() / public static void showarea() 修饰符顺序不对;/ 静态方法里不能直接用非静态属性/* circle c=new circle();*/3、分析如下程序,写出执行结果:/先静态块(只执行一次)方法块 构造方法public class blockdemopublic static void main(string口 args)person p= new person();person q= new person();p.sayhello()
8、;q.sayhello();class personstatic int eyenum ;string name;int age;double height;/非静态块non-static block);name=zhangsan;age=18;height =1.75;static /静态块static block);eyenum =2;public person() aaaaaaaaaaaa);public void sayhello()hello, my name is +name);static blocknon-static block aaaaaaaaaaaa non-static
9、 blockaaaaaaaaaaaahello, my name is zhangsanhello, my name is zhangsan田.编程题19. ( 1)定义一个人类person:1)定义一个方法sayhello() ,可以向对方发出问候语“hello,my name is xxx”2)有三个属性:名字、身高、体重( 2)定义一个personcreate 类:1)创建两个对象,分别是zhangsan, 33 岁, 1.73; lishi, 44 , 1.742)分别调用对象的sayhello()方法。(答案:person.java、personcreate.java)20. ( 1
10、)定义一个人类person:1)定义一个方法sayhello() ,可以向对方发出问候语“hello,my name is xxx”2)有三个属性:名字、身高、体重3)通过构造方法,分别给三个属性赋值( 2)定义一个constructor 类:1)创建两个对象,分别是zhangsan, 33 岁, 1.73; lishi, 44 , 1.742)分别调用对象的sayhello()方法。(答案:constructor.java、或者是 person3.java)21. ( 1)定义一个矩形类rectangle:1)定义三个方法:getarea()求面积、getper()求周长,showall()
11、分别在控制台输出长、宽、面积、周长。2)有 2 个属性:长 length 、宽 width3) 通过构造方法rectangle(int width, int length) ,分别给两个属性赋值 (答案:rectangle.java)22. 义一个点类 point,包含2个成员变量x、y分别表示x和y坐标,2个构造器point() 和 point(int x0,y0), 以及一个 movepoint ( int dx,int dy )方法实现点的位置移动。 () public class point privateintx0 ;privateinty0 ;public point() publ
12、ic point( int x0, int y0) t his . x0 =x0;this . y0 =y0;public void movepoint( int dx, int dy)t his . x0 = this . x0 + dx;t his . y0 = this . y0 + dy; 23. 写一个程序,创建两个 point对象pl、p2,分别调研 movepoint方法后,打印pl和p2的坐标。 public class point privateintx0 ;privateinty0 ;public point() public point( int x0, int y0)
13、t his . x0 =x0;this . y0 =y0; public void movepoint( int dx, int dy) t his . x0 = this . x0 + dx;t his . y0 = this . y0 + dy; 6.(1)定义一个动物类creature1)定义一个方法setsnarl(cat cat)可以设置动物发出猫的声音2)setsnarl(dog dog)可以设置动物发出狗的声音3)定义一个output()方法,可以输出动物的声音(2)要求定义一个猫类cat,具有猫的声音,将猫类传入动物类creature的吼叫方法setsnarl(cat cat)
14、可以设置动物发出猫的声音(3)要求定义一个狗类dog,具有狗的声音,将狗类传入动物类 creature的吼叫方法setsnarldog dog)可以设置动物发出狗的声音(4)定义一个 sound类,在main方法里调用 creature类的setsnarl()和output()方法分 别设置动物的声音和输出动物的声音效果显示:任务日控制台贸已弊itsound java 应用程序c:prograra filesjsvraj2rel啮喷1 1汪汪!?7.定义一个圆类 circle,描述圆对象。圆有一个属性radius表示半径,还有一个 findarea方法用于计算圆的面积。定义一个测试类。给半径赋
15、值为5,并且输出圆的面积。8、定义一个笔记本类,该类有颜色(char)和cpu型号(int)两个属性。(1)无参和有参的两个构造方法;有参构造方法可以在创建对象的同时为每个 属性赋值;(2)输出笔记本信息的方法然后编写一个测试类,测试笔记本类的各个方法。public class computetest public static void main(string args) computer c1 = new computer();c1.showcomputer();computer c2 = new computer( 红 , 32); c2.showcomputer();class com
16、puter privatechar color ;privateint cpunum ;public computer() public computer( char color, int cpunum) this . color = color;this . cpunum = cpunum;public char getcolor() return color ;public void setcolor( char color) this . color = color;public int getcpunum() return cpunum ;public void setcpunum(
17、int cpunum) this . cpunum = cpunum;public void showcomputer() 笔记本的颜色: + getcolor();笔记本的 cpu型号:+ getcpunum();9.定义一个汽车类 vehicle,要求如下:(1)属性包括:汽车品牌brand ( string类型)、颜色color (string类型)和速度speed (double 类型),并且所有属性为私有。(2)至少提供一个有参的构造方法(要求品牌和颜色可以初始化为任意值,但速度的初始值必须为0)。(3)为私有属性提供访问器方法。注意:汽车品牌一旦初始化之后不能修改。(4)定义一个一
18、般方法 run(),用打印语句描述汽车奔跑的功能定义测试类vehicletest,在其main方法中创建一个品牌为benz、颜色为black”的汽车。public class vehicle privatestringbrandprivatestringcolorprivatedoublespeedvehicle() vehicle(string brand,string color) this . brand = brand; this . color= color;speed = 0;publicstring getc010ro return color ;public void setc
19、olor(string color) this . color = color;public double getspeed() return speed ;public void setspeed( double speed) this . speed = speed;public void run()的+getbrand()+ 的速度是+getspeed(); public string getbrand() return brand ;二、 【选做题】1 、 ( 1 )编写一个时间类mytime ,包含一个构造方法, 3 个私有成员变量hour,minute,second 以及与它们相对
20、应的 get 与 set 方法(如 hour 有 gethour 和sethour 方法,分别表示获得和设置hour ) ,再加上一个转换成字符串的方法tostring 。( 2 )编写一个日期类mydate ,包含一个构造方法, 3 个私有成员变量year,month,day 以及与它们相对应的 get 与 set 方法, 再加上一个转换成字符串 的方法 tostring 。( 3 )编写一个fulltime 类,包含一个mytime 类型的私有成员变量 time 和一个 mydate 类型的成员变量date , 以及与它们相对应的 get 与 set 方法, 一个构造方法,再加上一个转换成
21、字符串的方法tostring 。(4)假设当前时间是2002 年 7 月 30 日 22 点 12 分 35 秒,编写一个程序,用 fulltime 类设置时间为以上时间,并打印。public class mytimetest public static void main(string args) mytime mytime = new mytime();mytime.sethour(20);mytime.setminute(20);mytime.setsecond(18);mydate mydate = new mydate();mydate.setyear(2012);mydate.se
22、tmonth(4);mydate.setday(10);+ mytime.tostring(); class mytime privateinthour ;privateintminuteprivateintsecondpublic intgethour() returnhour ;public void sethour( int hour) this . hour = hour;public int getminute() return minute ;public void setminute(int minute) this . minute = minute;public int ge
23、tsecond() return second ;public void setsecond( int second) this . second = second;overridepublic string tostring() return hour + 点 + minute + 分 + second + 秒 class mydate privateintyear ;privateintmonth ;privateintday ;publicintgetyear() return year ;public void setyear( int year) this . year = year
24、;public int getmonth() return month ;public void setmonth( int month) this . month = month;public int getday() return day ;public void setday( int day) this . day = day;overridepublic string tostring() return year + 年 + month + 月 + day + 日 ; 2 、设计一个类student ,该类包括姓名、学号和成绩。设计一个方法,按照成绩从高到低的顺序输出姓名、学号和成绩信息。public class student privatestringname ;privatestringnumber ;private int score ;public student() public student(string name, string number,int score) this . name = name;this. number = number;this. score = score;public string getname() return name ;public voi
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年重庆市新版基层法律工作考试试卷及答案
- 审核清单面向不同业务场景的审计工具
- 汉语国际教育硕士汉语基础(现代汉语)模拟试卷32(题后含答案及解析)
- 2025年佛山中考试题语文及答案
- 企业审计工作流程工具内控执行指南版
- 2024年国家职业资格考试《一级(高级技师)保育员》题库练习试卷附
- 企业宣传材料制作与发布工具
- 《2025年公共营养师(高级)考试试卷》-运动营养与能量补充试题
- 2025年全国共青团“新团员入团”应知应会知识考试能力检测试卷及完整答案详解(有一套)
- 2022年湖南理工学院汉语言文学专业《现代汉语》期末试卷A(有答案)
- 2024年安全学院危险性较高企业安全管理人员业务能力培训测试考试真题
- 2024年注册安全工程师考试真题及答案(完整版)
- 公路养护机械管理方案(3篇)
- 消息写作课程讲解
- 4.1人民民主专政的本质:人民当家作主 课件 高中政治统编版必修三政治与法治
- 医院网络信息安全培训
- 智能制造传感技术
- 肿瘤患者化疗后胃肠道反应管理
- 《建筑业10项新技术(2025)》全文
- 重庆下浩里招商手册
- 大中国课件幼儿
评论
0/150
提交评论