构造函数调用存储在哪里?堆栈还是堆? [英] Where does the constructor invocation get stored? Stack or Heap?

查看:653
本文介绍了构造函数调用存储在哪里?堆栈还是堆?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建对象并调用构造函数时,构造函数调用存储在何处?它是在堆栈还是堆上?

When an object is created and the constructor is called where does the constructor invocation get stored? is it on a stack or heap?

推荐答案

堆仅用于存储对象。没有办法在堆上调用构造函数。

Heap is only meant for storing objects . There is no way to have constructor invoked on heap.

它的调用是在堆栈上完成的。

Stack用于方法调用。它用于创建方法堆栈。虽然构造函数不是一种方法。但是你可以随时写任何逻辑或赋值任何方法。所以它像任何其他方法一样在堆栈中实现。

Stack is used in method calling. It is used for creating method stacks. Although constructor is not a method. But you can always write any logic or assignment as is always done In any method. So it's implemented in a stack like any other method.

这篇关于构造函数调用存储在哪里?堆栈还是堆?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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