《Java基础入门》-课后习题答案--1-6 联系客服

发布时间 : 星期三 文章《Java基础入门》-课后习题答案--1-6更新完毕开始阅读0bb663317b563c1ec5da50e2524de518964bd318

}

2、参考答案

class Father {

}

public class Test02 {

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

Father.Child child = new Father().new Child(); child.introFather();

private String name = \class Child { }

public void introFather() { }

System.out.println(\

}

第4章 面向对象(下)

一、填空题

1、继承

2、方法,抽象类 3、import

4、子类、父类、基类 5、Exception 6、final 7、super 8、Object 9、try、catch

10、jar –cvf,java –jar 二、判断题

1、错 2、对 3、错 4、对 5、对 三、选择题

1、B 2、C 3、ABC 4、 ABCD 5、C 6、AC 7、C 8、D 9、A 10、B 四、程序分析题

1、程序编译能通过,这是因为int x = 2 / 0; System.out.println(x);这两条语句使用了try块,捕获了程序因为除以0而产生的异常情况,之后程序会继续向下执行,输出“进入catch代码块”,“进入finally代码块”。

2、程序编译不通过,这是因为在程序中使用了final关键字修饰Animal类,使得Animal类不能被继承。shout()方法中同样使用了final关键字,使得该方法不能被重写。 3、程序编译能通过,输出结果为“动物叫!”和“汪汪……”,因为在程序中调用shout()方法时,首先会通过super.shout()调用父类的方法说出“动物叫!”之后再输出“汪汪……”

4、程序编译不通过,因为接口中定义的方法不能有方法体,所以定义的eat()方法是错误的。接口中的方法必须在子类中全部实现,由于run()方法在子类中并没有重新实现,所以这也是错误的。

精选

五、简答题

1、在继承关系中,子类的方法与父类的某一方法具有相同的方法名、返回类型和参数列表,则称子类的该方法重写(覆盖)父类的方法。

2、多态意味着一个对象有着多种形态,可以在特定的情况下,表现不同的状态,从而对应着不同的属性和方法。简单的说,多态就是使用父类类型的变量引用子类对象,根据被引用子类对象的特性,程序会得到不同的运行效果。

3、在Java中,使用abstract关键字修饰的类称之为抽象类。抽象类是不能被实例化的,通常需要写一个子类来继承抽象类,同时实例化子类来获得该类的对象。抽象类通常用于表示一种抽象的概念。 接口可以说是一种特殊的抽象类,接口中只能定义常量和抽象方法。由于接口的特殊性,在定义时需要使用interface关键字。

六、编程题

1、参考答案

class Student { }

class UnderGraduate extends Student{ }

public class Test01{ }

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

Student student = new Student(\student.show();

UnderGraduate underGraduate = new UnderGraduate(%underGraduate.show(); public String degree;

public UnderGraduate(String name,int age,String degree){ }

public void show(){ }

System.out.println(\super(name, age); this.degree=degree; public String name; public int age;

public Student(String name,int age){ }

public void show(){ }

System.out.println(\this.name=name; this.age=age;

2、参考答案

interface Shape {

double area(double givenValue);

精选

}

class Square implements Shape{ }

class Circle implements Shape{ }

public class Test02 { }

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

Shape square = new Square(); Shape circle = new Circle();

System.out.println(square.area(2)); System.out.println(circle.area(3)); public double area(double r) { }

return Math.PI*r*r;

public double area(double sideLength) { }

return sideLength*sideLength;

3、参考答案

class NoThisSongException extends Exception{ }

class Player{ }

public class Test03 {

public static void main(String[] args) {

Player player = new Player(); try {

player.play(13);

} catch (NoThisSongException e) { }

System.out.println(\异常信息为: \

public void play(int index)throws NoThisSongException{ }

if(index>10){ }

System.out.println(\正在播放歌曲\

throw new NoThisSongException(\您播放的歌曲不存在\

public NoThisSongException(){ }

public NoThisSongException(String message){ }

super(message); super();

精选

}

}

第5章 多线程

第6章 JavaAPI

一、填空题

1、 String、StringBuffer

2、 Date、Calendar、DateFormat

3、 getRuntime() 4、 sqrt()

5、 DateFormat 6、 π、e

7、 Random、java.util

8、 length() 9、 静态 10、edcba 二、判断题

1、错 2、错 3、对 4、错 5、对

三、选择题

1、C 2、C 3、D 4、C 5、C 6、B 7、C 8、A 9、A 10、B 四、程序分析题

1、程序编译能通过,输出结果如下

5 7.0 -8.0 -5 8.1 -6.1

2、程序编译能通过,输出结果如下

str.length():15 str.charAt(0):d lastIndexOf(m):10 substring(2,4):fe indexOf(g):5

五、简答题

1、String类是不可变类,即字符串值一旦初始化后就不可能改变。StringBuffer是可变字符串类,类似String的缓冲区,可以修改字符串的值。

2、Date类用来表示某个特定的瞬间,能够精确到毫秒。而在实际应用中,往往需要把一个日期中的年、月、日等信息单独返回进行显示或处理,这个类中的大部分方法都已被标记过时。Calender

精选