云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > JAVA期末复习资料

JAVA期末复习资料

  • 62 次阅读
  • 3 次下载
  • 2025/6/6 4:44:24

} }

3、编写程序实现窗口,包含一个标签、一个文本框和一个按钮,当用户单击按钮时,程序把文本框中的内容提制到标签中。 //引入相关包

public MyFrame{

public MyFrame(){

JFrame fr = new JFrame(); //设置窗体的布局为FlowLayout

JLabel lbl = new JLabel(“Init info”); JTextField txt = new JTextField(30); JButton btn = new JButton(“Sure”); fr.add(lbl); fr.add(txt); fr.add(btn);

//给按钮注册监听器

//使用窗体可见,并设置大小

}

//定义内部类监听ActionEvent事件 {

public void actionPerformed(ActionEvent e){ lbl.setText(txt.getText()); } }

public static void main(String[] args){ new MyFrame(); } }

4、仔细阅读下面的程序代码,请将划线上①~⑤的语句补充完整。 abstract class Person{ private String name;

public Person(String n){ name = n; }

public ____________ String getDescription(); public _____________ (){ return name; } }

class Student ____ _________ Person{ private String major;

public Student(String n, String m){ super(n); major = m; }

public String _____________(){ return \学生专业是:\ } }

public class TestPerson{

public static void main(____________){

Person p = new Student(\王甜甜\计算机科学\

System.out.println(p.getName() + \ } }

5、阅读下面的程序代码,根据注释要求补充、完成代码(划线是需要补充的地方),最后简要说明该程序的功能。

___________________{ //声明一个接口,接口名为Area public double CalsulateArea(); }

{//定义圆类Mycircle实现接口Area double r;

public MyCircle(double r){ this.r=r; }

{//实现接口中的方法 return Math.PI*r*r; } }

class MyRectangle implements Area{ double width,height;

public MyRectangle(double w,double h){ width=w; height=h; }

public double CalsulateArea(){ return width*height; } }

class TestArea{

public static void main(String []args){

//创建MyCircle的对象,对象名为c ,

半径为5

System.out.println(\ } }

6、定义一个抽象类AbstractTest,其中有一个公共的抽象方法printMsg()。然后定义此抽象类的一个子类DefaultTest,包括的成员变量有姓名,学号,分数,且此类中包括二个构造方法。

abstract class AbstractTest{

}

{ String name; String id; int score;

//接收三个参数的构造方法

//接收姓名和学号二个参数的构造方法

//实现抽象方法,方法体为打印出学生的姓名与成绩 }

7、定义接口Student,该接口中有一个无参、无返回值的方法prtMsg;定义类College,包括的私有属性有id和name,包括一个接收学生学号和姓名的构造方法,并且实现Student接口。

interface Student{

}

//College类的声明,实现Student接口 {

//定义私有成员变量id和name,类型自定

//构造方法声明和定义,接收二个参数 //实现prtMsg方法的声明 {

//prtMsg的方法体

System.out.println(id + name); } }

8、 定义类Stu,并把该类放在当前目录下的包com中:

包括的成员变量有:常量classid,类变量school,公共成员变量id和name,私有成员变量age。

包括的方法有:一个具有二个参数的构造方法;公共静态方法getSchool();主方法。 //把该类放在当前目录下的包com中

public class Stu{

//字符串常量classid //字符串类变量school,并把其值初始化为 “YEU”

private int age; public String id; public String name;

//构造方法声明,接收二个参数ids和names

{

id = ids; name = names; }

//公共静态方法getSchool()的声明 {

return school; }

//主方法

public static void main(String[] args){ System.out.println(Stu.getSchool()); System.out.println(Stu.school); } }

五、程序改错题

1、阅读下面的程序,修改程序中编译错误的地方(提示:共五处错误) interface Shape{ double PI;

public double area( );

public double perimeter( ); }

class Cycle extends Shape{ private double r;

public Cycle(double r){ this.r=r; }

double area( ){

System.out.println(PI*r*r); } }

public class Test{

public static void main(String args[]){ Cycle c=new Cycle(1.5);

System.out.println(\面积为:\

} }

2、阅读下面的程序,修改程序中错误的地方(提示:共四处错误) 1. class Person{

2. private String name; 3. private int age; 4. private String sex; 5. static int count=0;

6. public Person(String name,int age,String sex){ 7. this.name=name; 8. this.age=age; 9. this.sex=sex; 10. }

11. public void setAge(int age){ 12. this.age=age; 13. }

14. public void setCount(){ 15. count++; 16. }

17. public void toString(){

18. return \ 19. } 20. }

21. public class TestPerson{

22. public static void main(String args[]){ 23. Person p=new Person(\张三\男\24. p.age=21;//修改年龄为21 25. p.setCount();

26. System.out.println(Person.tostring()); 27. } 28. }

搜索更多关于: JAVA期末复习资料 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

} } 3、编写程序实现窗口,包含一个标签、一个文本框和一个按钮,当用户单击按钮时,程序把文本框中的内容提制到标签中。 //引入相关包 public MyFrame{ public MyFrame(){ JFrame fr = new JFrame(); //设置窗体的布局为FlowLayout JLabel lbl = new JLabel(“Init info”); JTextField txt = new JTextFi

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com