继承中的对象关系 [英] Object relationship in inheritence

查看:85
本文介绍了继承中的对象关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个A类.假设B类扩展了A.

当我创建B的实例时..创建两个对象,一个为A,另一个为B .....这两个对象如何关联,指定此A对象仅与该B对象相关....

i am having a class A .suppose the class B extends A .

when i am creating the instance of B ..two objects are created one for A and other for B.......how this two objects are related specifying this A object is related to only this B object....

class A{}


class B extends A{

  public static void main(String[] args){
 
      B b = new B(); 
      }
   }


在这里,为超类A和子类B创建了两个对象...

与此B相关的特定A对象的方式.......


here two objects are created one for the super class A and for the subclass B...

how the specific A object related to this b.......

推荐答案

都调用了两个构造函数,但是仅创建了一个对象,并且该对象的类型B.阅读OOP的基础知识.
Both constructors are called, but only one object is being created and that is of type B. Read the fundamentals of OOP.


请参见此处 [ ^ ]更多详细信息.
See here[^] for more details.


这篇关于继承中的对象关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆