Documentation

The Java™ Tutorials
Hide TOC
Questions and Exercises问题和练习
Trail: Learning the Java Language
Lesson: Interfaces and Inheritance

Questions and Exercises: Inheritance问题和练习:继承

Questions问题

1. Consider the following two classes:考虑下面两个类:

public class ClassA {
    public void methodOne(int i) {
    }
    public void methodTwo(int i) {
    }
    public static void methodThree(int i) {
    }
    public static void methodFour(int i) {
    }
}

public class ClassB extends ClassA {
    public static void methodOne(int i) {
    }
    public void methodTwo(int i) {
    }
    public void methodThree(int i) {
    }
    public static void methodFour(int i) {
    }
}

a. Which method overrides a method in the superclass?哪个方法重写超类中的方法?
b. Which method hides a method in the superclass?哪个方法在超类中隐藏方法?
c. What do the other methods do?其他的方法是什么?

2. Consider the Card, Deck, and DisplayDeck classes you wrote in Questions and Exercises: Classes. 考虑你在问题和练习:类中写的Card类、Deck类和DisplayDeck类。What Object methods should each of these classes override?这些类中的每一个都应该覆盖哪些Object方法?

Exercises练习

1. Write the implementations for the methods that you answered in question 2.为您在问题2中回答的方法编写实现。


Check your answers.检查你的答案。


Previous page: Summary of Inheritance
Next page: Numbers and Strings