Computer Science, asked by sayanbiswas1526, 1 year ago

Why are destructors rarely used in java but essential in c++?

Answers

Answered by danielochich
2
Destructors are rarely used in java.

REASONS

Java has its own built in garbage collecting program therefore requires no destructor.

This is made possible since Java has :

1.) The ability to assign null thus hasten destruction.


2.) It employs the use of finalizers and reference types which are essential in noticing that an object is about to be destroyed.


3.) It can define close () on any given object thus having it do something appropriate and necessary.

These features make Java to function even without destructors hence they are rarely used.
Answered by mindfulmaisel
0

EXPLANATION:

  • Unlike C++, the java has built in garbage collection program. These garbage collectors acts as destructors and hence, java does not need any destructors.  
  • Garbage collector can be defined as a program which manages the memory automatically.  
  • When the object is no more in need of references, then it is assumed to be no longer needed and the respective memory can be reclaimed automatically. Thus there is no need to destroy the object explicitly.

Learn more about destructors

Constructor and destructors in c++

https://brainly.in/question/367146

What is consructor and destructor in c++?

https://brainly.in/question/3748041

Similar questions