What is the difference between the destructor and the Finalize() method? When does the Finalize() method get called?

1 Answer

Answer :

Finalize() corresponds to the .Net Framework and is part of the System.Object class. Destructors are C#'s implementation of the Finalize() method. The functionality of both Finalize() and the destructor is the same

Related questions

Description : What is Finalize() Method of Object class?

Last Answer : Each class in C# is automatically (implicitly) inherited from the Object class which contains a method Finalize(). This method is guaranteed to be called when your object is garbage collected

Description : What is Destructor?

Last Answer : A destructor is just opposite to constructor. it has same as the class name, but with prefix ~ (tilde). They do not have return types

Description : Whait is Method overriding?

Last Answer : Method overriding occurs when child class declares a method that has the same type arguments as a method declared by one of its superclass. By declaring base class function as virtual, we allow the function to be overridden in any of derived class

Description : What is a Method Overloading?

Last Answer : Method with same name but with different arguments is called method overloading

Description : Can you allow a class to be inherited, but prevent the method from being overridden?

Last Answer : Yes. Just leave the class public and make the method sealed

Description : What is Static Method of the class?

Last Answer : Methods that you can call directly without first creating an instance of a class. 1. As static methods may be called without any reference to object

Description : What is Interface?

Last Answer : An Interface is a group of constants and method declaration interface like classes, define a set of properties, methods, and events. But unlike classes, interfaces do not provide implementation

Description : How many types of Access Modifiers?

Last Answer : Public – Allows the members to be globally accessible. Private – Limits the member’s access to only the containing type. Protected – Limits the member’s access to the containing type and all classes derived from the containing type. Internal – Limits the member’s access to within the current project

Description : What is Polymorphism?

Last Answer : Polymorphism means same operation may behave differently on different classes. Example : 1. Method Overloading and Method Overriding

Description : Is .NET C# supports Multiple inheritance?

Last Answer : Multiple inheritance of classes is not allowed in C#. but In C# you can implements more than one interface, thus multiple inheritance is achieved through interface

Description : Can you prevent your class from being inherited by another class?

Last Answer : Yes. The keyword “sealed” will prevent the class from being inherited.

Description : What are Sealed Classes in C#?

Last Answer : The sealed modifier is used to prevent derivation from a class

Description : What is an Inheritance?

Last Answer : The process of sub-classing a class to extend its functionality is called Inheritance. Advantage : It provides idea of reusability.

Description : What is ref keyword & out keyword?

Last Answer : Refrence Variable “must” be initialized before it is passed into a method.

Description : What is Value Type and Reference Type?

Last Answer : A variable is value type or reference type is solely determined by its data type. Ex: int, float, char, decimal, bool, decimal, struct, etc are value types As name suggest Reference Type stores reference to the ... ; Y = X; Console.writeline(Y.value); Y.value = 50; Console.writeline(X.value);

Description : What is Enumeration?

Last Answer : Enumeration improves code readability. It also helps in avoiding typing mistake

Description : What is a Garbage collection?

Last Answer : Garbage collection is the mechanism that reclaims the memory resources of an object when it is no longer referenced by a variable. And Net Runtime performs automatically performs garbage collection

Description : What is Static Constructor?

Last Answer : In C# it is possible to write a static no-parameter constructor for a class. Such a class is executed once, when first object of class is created. Class MyClass { static MyClass() { //Initialization Code for static fields and properties. } }

Description : What is static member of a calss?

Last Answer : Static members belong to the whole class rather than to individual object Static members are accessed with the name of class rather than reference to objects

Description : What is Constructor?

Last Answer : A constructor is a special method whose task is to initialize the object of its class. 1. It is special because its name is the same as the class name 2. They do not have return ... can call the base class constructor 4. Constructor is invoked whenever an object of its associated class is created

Description : Whar are properties?

Last Answer : Attribute of object is called properties Example:- A car has color as property.

Description : What is an encapsulation?

Last Answer : Wrapping up of data and function into a single unit is known as Encapsulation.

Description : What is an Object?

Last Answer : Instance of Class is called object. An object is created in memory using keyword “new”.

Description : What is a Class?

Last Answer : A user-defined data structure that groups properties and methods. Class doesn’t occupies memory.

Description : How can we suppress a finalize method?

Last Answer : GC.SuppressFinalize()

Description : State use of finalize( ) method with its syntax.

Last Answer : Use of finalize( ): Sometimes an object will need to perform some action when it is destroyed. Eg. If an object holding some non java resources such as file handle or window character font, then before ... method whenever it is about to recycle an object. Syntax: protected void finalize() { }  

Description : Is it possible to return an entire linked list object from a method in C++ without running the destructor?

Last Answer : Your description in the problem doesn't really describe what you want it to do that you would call right, nor does it explain how it uses its linked list. If you haven't figured out exactly what you want ... want to do that you can describe clearly, then yes, there will be a right way to do it.

Description : Define what is the difference between “finalize” and “finally” methods in C#?

Last Answer : Finalize – This method is used for garbage collection. So before destroying an object, this method is called as part of the cleanup activity. Finally – This method is used for executing the code irrespective of exception occurred or not.

Description : Define what is the difference between “dispose of” and “finalize” variables in C#?

Last Answer : Dispose of - This method uses interface - IDisposable interface and it will free up both managed and unmanaged codes like - database connection, files, etc. Finalize - This method is called internally ... called explicitly. It is called by the garbage collector and can't be called from the code.

Description : Can a newborn be refused his father's last name if the mom was previously married, and didn't finalize the divorce?

Last Answer : Um the lady in charge is referring to some kind of nurse-administrator, right? My suggestion would be to raise A WHOLE BUNCH OF HELL and speak to her supervisor and ask to see the portion of the ... in the hospital has any authority over the name at all. Then ask to speak to the hospital attorney.

Description : What do you need to do to finalize divorce papers in Illinois?

Last Answer : A divorce is not final until it signed by a judge. You will need too have your paperwork reviewed by a judge.

Description : How much time it took for Constituent Assembly to finalize the constitution?

Last Answer : 2 Years 11 Months 18 Days

Description : What is the last item a project manager must do to finalize project close-out? 1. Reassign the team  2. Contract completion  3. Archive the project records  4. Complete lessons learned  5. None of the above.

Last Answer : 2. Contract completion

Description : The end of your world is upon you, and you are the one to choose how it all goes down. Which form of the destructor do you choose?

Last Answer : I would choose instant painless death of all sentient creatures via things like rapid brain aneurysms, followed by the planet collapsing into a black hole. I’m not sure what the most gruesome way would be, but imposing this on everyone seems like a decent start.

Description : Is constructor or destructor inheritance explicit or implicit? What does this mean?

Last Answer : Constructor or destructor inheritance is explicit…. Public Extended : base() this is called the constructor initializer.

Description : What is a destructor?

Last Answer : A C# destuctor is not like a C++ destructor. It is actually an override for Finalize(). This is called when the garbage collector discovers that the object is unreachable. Finalize() is called before any memory is reclaimed.

Description : Which of the following is true about Java. A) Java does not support overloading. B) Java has replaced the destructor function of C++ C) There are no header files in Java. D) All of the above.

Last Answer : D) All of the above

Description : State True or False i) A destructor never takes any argument nor does it return any value. ii) It releases memory space for future use. A) True, True B) True, False C) False, True D) False, False

Last Answer : A) True, True

Description : Write any two characteristics of destructor.

Last Answer : Characteristics: 1. It is used to destroy objects created by a constructor. 2. Name of destructor and name of the class is same. 3. Its name is preceded with tilde (~) symbol. 4. It ... the compiler upon exit from the program (or block or function) i.e when scope of object is over.

Description : What is destructor? How destructor is declared? When destructor is invoked?

Last Answer : Destructor: A destructor is a special member function used to destroy the objects that are created by a constructor. Declaration: Destructor is declared in public section of a class. It is member function ... from the program (or block or function) to clean up storage that is no longer accessible. 

Description : Write a program to declare class having data member as hrs, mins, secs. Write constructor to assign values and destructor to destroy values. Accept & display data for one object.

Last Answer : #include<iostream.h> #include<conio.h> class time { private: int hrs, mins,sec; public: time(int h,int m,int s) { hrs=h; mins=m; sec=s; } ~time() { cout<< hours ... } }; void main() { time t(2,43,56); t.display(); getch(); }

Description : Explain destructor with suitable example. 

Last Answer : Destructor: 1. A destructor is a special member function whose task is to destroy the objects that have been created by constructor. 2. It does not construct the values for the data members of the class. 3. It is invoked ... main() { time t(2,43,56); t.display(); getch(); }

Description : Differentiate between constructor and destructor. 

Last Answer : Differentiate between constructor and destructor.

Description : Which of the following, in C++, is inherited in a derived class from base class ? (A) constructor (B) destructor (C) data members (D) virtual methods

Last Answer : (C) data members

Description : Implicit return type of a class constructor is: (A) not of class type itself (B) class type itself (B) a destructor of class type (D) a destructor not of class type 

Last Answer : (B) class type itself

Description : State the rules for writing destructor function.

Last Answer : Rules for writing destructor function are: 1) A destructor is a special member function which should destroy the objects that have been created by constructor. 2) Name of destructor and name of the class should ... should not be classified in any types. 7) A class can have at most one destructor.