继承中的对象关系

编程入门 行业动态 更新时间:2024-10-22 08:18:23
本文介绍了继承中的对象关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个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.

更多推荐

继承中的对象关系

本文发布于:2023-11-17 02:17:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1608445.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对象   关系

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!