求《Java程序设计教程》 牛晓太主编 清华大学出版社出版 课后习题答案 ……急需

求《Java程序设计教程》 牛晓太主编 清华大学出版社出版 课后习题答案 ……急需,第1张

>

3, 文件名:Threejava

public class Three {

public static void main(String[] args) {

Student stu = new Student("Zhang San", true, (short)12);

Systemoutprintln("Student name: " + stuname);

Systemoutprintln("Student is a male: " + stusex);

Systemoutprintln("Student's age: " + stuage);

stuwork();

stustudy();

Teacher teacher = new Teacher();

teacherlearnMoney();

}

}

abstract class Person{//抽象类Person

protected String name;

protected boolean sex;

protected short age;

protected abstract void work(); //work抽象方法

}

interface Learnmoney{//Learnmoney接口

public void learnMoney();

}

interface Study{//Study接口

public void study();

}

class Student extends Person implements Study{//Student类

public void work() {

Systemoutprintln("学生的工作是努力学习");

}

public Student(String name, boolean sex, short age){

supername = name;

supersex = sex;

superage = age;

}

public void study() {

Systemoutprintln("学生正在学习");

}

}

class Teacher extends Person implements Learnmoney{

public void work() {

Systemoutprintln("教师的工作是教书育人");;

}

public void learnMoney() {

Systemoutprintln("教师正在赚钱");

}

}

class Docotor extends Person implements Learnmoney{

public void work() {

Systemoutprintln("医生的职责是救死扶伤");

}

public void learnMoney() {

Systemoutprintln("医生正在赚钱");

}

}

------------------------------------

4文件名:Fourjava

public class Four {

public static void main(String[] args) {

Rectangle r = new Rectangle(3, 4);

Systemoutprintln("Area is : " + rarea());

Systemoutprintln("Circle is: " + rcircle());

}

}

class Rectangle{

private double width;

private double height;

public Rectangle(double width, double height){

thiswidth = width;

thisheight = height;

}

public double circle(){//求周长

return (width + height) 2;

}

public double area(){//求面积

return width height;

}

}

--------------------

5Fivejava

public class Five {

public static void main(String[] args) {

AImpl a = new AImpl();

apaint();

}

}

interface A {

public int method1(int x);

public int method2(int x, int y);

}

class AImpl implements A{

public int method1(int x) {

return (int)Mathpow(x, 5);

}

public int method2(int x, int y) {

return x > y x: y;

}

public void paint(){

int result1 = method1(2);

int result2 = method2(2, 8);

Systemoutprintln("method1(2) = " + result1);

Systemoutprintln("method2(2, 8) = " + result2);

}

}

-----------------------------测试

method1(2) = 32

method2(2, 8) = 8

1要激活一个java小应用程序applet需具有 class 文件。

2一个java源程序文件必须以 java为其扩展名。

3java编译器产生的文件的扩展名为 class。

4每个java程序语句以 分号 结束。

5所有程序均可以用 顺序结构,分支结构 和 循环结构 三种控制结构编写。

6一个只有在定义它的方法中可知的变量称为 局部变量

7被调用方法中的 return 语句可以将表达式的值回送给调用它方法。

8方法头中的关键字void 用来表示方法不还返回值。

9当applet开始执行时,调用一次init 方法。

10在java中可以使用许多方法同名,但各方法使用的参数的类型和数量不同,这称为方法 重载。

11限定词final 用来声明只读变量。

12指定为private 的类成员只能被此类中的成员访问。

13类的方法通常设为public,而类的实例变量一般设为private指定为 static的类成员可被此类作用域中的任何对象访问。

15关键字final表明一个对象或变量在初始化后不能被修改。

16声明为static的方法不能访问 非静态 类成员。

17如Alpha类继承Beta类,Alpha类被称为 子 类,Beta类被称为 父 类。

18四种成员访问限制是 public ,protected,private,friendly。

19如果一个类包含了一个或多个abstract方法,它是 抽象 类。

20线程通过调用sleep() 方法可以休眠一段时间,然后恢复运行。

21Applet类的 getImage()方法将图像装入applet。

22FileOutputStream、FileInputStream、RandomAccessFile文件流类的 close() 方法,可用于关闭文件。

23鼠标被移动时会发生 MouseEvent 事件。

24使用setLayout() 方法为构件容器设置布局管理器。

25Java的网络类在javanet包中

以上就是关于求《Java程序设计教程》 牛晓太主编 清华大学出版社出版 课后习题答案 ……急需全部的内容,包括:求《Java程序设计教程》 牛晓太主编 清华大学出版社出版 课后习题答案 ……急需、求《JAVA程序设计标准教程》 邱加永编 课后选择习题答案、Java程序设计题目等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/zz/9394062.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-27
下一篇2023-04-27

发表评论

登录后才能评论

评论列表(0条)

    保存