inheritance中文Java语言,Java语言程序设计基础篇课后题答案-Chapter 9 Inheritance and Polymorphism...

Chapter 9 Inheritance and Polymorphism

1. (a) The printout is

A’s no-arg constructor is invoked

(b) The default constructor of B attempts to invoke the default of constructor of

A, but class A's default constructor is not defined.

2. All false.

(1) A subclass is an extension of a superclass and normally contains more details

information than its superclass.

(2) If a subclass’s constructor explicitly invoke a superclass’s constructor, the

superclass’s no-arg constructor is not invoked.

(3) You can only override accessible instance methods.

(4) You can only override accessible instance methods.

3. The following lines are erroneous:

{

radius = radius; // Must use this.radius = radius

}

class B extends Circle (missing extends)

{

Circle(radius); // Must use super(radius)

length = length; // Must use this.length = length

}

public double getArea()

{

return getArea()*length; // super.getArea()

}

4. Method overloading defines methods of the same name in a class. Method

overriding modifies the methods that are defined in the superclasses.

5. Yes, because these two methods are defined in the Object class; therefore, they

are available to all Java classes. The subclasses usually override these methods to

provide specific information for these methods.

The toString() method returns a string representation of the object; the equals()

method compares the contents of two objects to determine whether they are the

same.

6. B’s constructor is invoked

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值