(7-1)定义了Animal类、Cat类和Dog类,则代码段是正确的。
class Animal{ };
class Cat extends Animal{}
class Dog extends Animal{}
class Animal{ };
class Cat extends Animal{}
class Dog extends Animal{}
Cat[]a = new Cat[5]; a[0] = new Cat();
举一反三
- 下列各种java类的定义,那种是错误的 A: class Animal{}class Dog extends Animal {} B: final class Animal{}class Dog extends Animal{} C: abstract class Animal{}class Dog extends Animal{} D: public class Animal{}class Dog extends Animal{}
- (7-1)定义了Animal类、Cat类和Dog类,则()代码段是正确的。classAnimal{};classCatextendsAnimal{}classDogextendsAnimal{} A: Dog[] a = new Dog[5];a[0] = new Cat(); B: Animal a = new Animal[5];a[0] = new Animal(); C: Dog[]a = new Dog[5];a[0] = new Animal(); D: Cat[]a = new Cat[5];a[0] = new Cat();
- class Animal { public Animal() { System.out.println("Animal!"); } } public class Dog extends Animal{ public Dog() { System.out.println("Dog!"); } public static void main(String[] args) { Dog dog=new Dog(); } }
- 定义了Animal类、Cat类和Dog类,则()代码段是正确的。classAnimal{};classCatextendsAnimal{ }classDogextendsAnimal{ } A: Dog[ ] ds=new Dog[5];ds[0]=new Animal(); B: Animal[ ] as=new Animal[5];as[0]=new Dog();
- 若Animal是Cat,Dog的父类,则下列选项中,正确的是() A: Animal animal = new Cat(); B: Cat cat = (Cat)new Animal(); C: Animal animal = new Dog(); D: Cat cat = (Cat)new Dog();
内容
- 0
Animal 是抽象类 ,Dog类和Cat类继承了Animal 。Animal dog = new Dog();的写法是否正确?
- 1
若Animal是Cat,Dog的父类,则下列选项中,正确的是() A: Animal animal = new Cat(); B: Animal a = new Cat(); Cat cat = (Cat) a; C: Animal animal = new Dog(); D: Cat cat = (Cat)new Dog();
- 2
下列代码声明了3个类class Animal{};class Cat:publicAnimal{};class Mouse:Animal{};下列关于这些类之间关系的描述中,错误的是: A: 类Animal是类Cat的基类 B: 类Mouse从类Cat公有继承 C: 类Cat是类Animal的派生类 D: 类Mouse是类Animal的派生类
- 3
下列代码声明了3个类 class Animal{}; class Cat:publicAnimal{}; class Mouse:Animal{}; 对于这段代码,理解错误的是:
- 4
在前面几题的基础上,有子类Dog和Cat继承了父类Animal,如下空格的输出是以下哪个选项?dog = Dog(coco,small); cat = Cat(kawaii)>>> isinstance(dog, Animal)___________>>> isinstance(cat, Animal)___________>>> isinstance(dog, Dog)___________>>> isinstance(dog, Cat)____________