• 2022-06-14
    若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();
  • A,C

    内容

    • 0

      (7-1)定义了Animal类、Cat类和Dog类,则代码段是正确的。 class Animal{ }; class Cat extends Animal{} class Dog extends Animal{}

    • 1

      ‏在前面几题的基础上,有子类Dog和Cat继承了父类Animal,如下空格的输出是以下哪个选项?‍‏dog = Dog('coco','small'); cat = Cat('kawaii') >>> isinstance(dog, Animal) ___________ >>> isinstance(cat, Animal) ___________ >>> isinstance(dog, Dog) ___________ >>> isinstance(dog, Cat) ____________‍ A: True True False False B: True True True False C: True False False True D: True True True True

    • 2

      若Animal 是Cat,Dog的父类,则下列选项中,正确的是()

    • 3

      创建⼀个⽗类Animal,⼀个⼦类Cat,Animal three = new Cat();不是()? A: 向上转型 B: ⾃动转型 C: 向下转型 D: 隐式转型

    • 4

      若有父类Animal及其两个子类Cat、Dog,则以下类型转换正确的有( )