有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java实例和对象不同吗?

以下哪项是正确的

  1. b不是A的一个例子
  2. b不是C的一个例子
class A{}
class B extends A{}
class C extends B{}

B b=new B();  

共 (1) 个答案

  1. # 1 楼答案

    为了帮助您理解这个概念,您可以将抽象名称A, B, C替换为常见示例,例如Animal, Feline, Cat

    就像

    class Animal {}
    class Feline extends Animal {}
    class Cat extends Feline {}
    

    你的问题变成:

     1. One feline might not be an Animal
     2. One feline might not be a Cat
    
    1. 错每只猫都是动物。猫科动物
    2. 的确,并不是每只猫都是猫。猫科动物不会延伸到猫科动物身上

    正如@AndyTurner所提到的,你可以使用instanceOf来查看它