What is virtual constructors/destructors?

1 Answer

Answer :

Answer1
Virtual destructors:
If an object (with a non-virtual destructor) is destroyed explicitly by applying the delete  operator to a base-class pointer to the object, the base-class destructor function (matching  the pointer type) is called on the object.
There is a simple solution to this problem declare a virtual base-class destructor. This makes all derived-class destructors virtual even though they don‟t have the same  name as the base-class destructor. Now, if the object in the hierarchy is destroyed  explicitly by applying the delete operator to a base-class pointer to a derived-class object,  the destructor for the appropriate class is called. Virtual constructor: Constructors cannot  be virtual. Declaring a constructor as a virtual function is a syntax error.  
Answer2
Virtual destructors: If an object (with a non-virtual destructor) is destroyed explicitly by  applying the delete operator to a base-class pointer to the object, the base-class destructor  function (matching the pointer type) is called on the object.
There is a simple solution to this problem – declare a virtual base-class destructor. This  makes all derived-class destructors virtual even though they don‟t have the same name as  the base-class destructor. Now, if the object in the hierarchy is destroyed explicitly by  applying the delete operator to a base-class pointer to a derived-class object, the  destructor for the appropriate class is called.

Related questions

Description : Explain what constructors and destructors are and describe what they are used for.

Last Answer : The constructor is the method that initializes a class or structure and is run when a type is first instantiated. It is used to set default values and perform other tasks required by the class. ... reclaimed by garbage collection. It contains any code that is required for cleanup of the object. 

Description : Define what are constructors and destructors?

Last Answer : Constructors and destructors are special methods. Constructors and destructors are special methods for every class. Each class has its own constructor and destructor and are called automatically when the ... access the class and the destructor destroys them when the objects are not required anymore.

Description : Virtual constructor: Constructors cannot be virtual. Declaring a constructor as a virtual function is a syntax error. Does c++ support multilevel and multiple inheritance?

Last Answer : Yes.

Description : Which of the following characteristics of constructor are true. i) They should be declared in the public section. ii) They are invoked automatically when the objects are created. iii) They do not have return type and void also. ... and v C) Only i, iii, iv and v D) All i, ii, iii, iv and v

Last Answer : D) All i, ii, iii, iv and v

Description : Can you use access modifiers with destructors? 

Last Answer : No

Description : If a base class has a number of overloaded constructors, and an inheriting class has a number of overloaded constructors; can you enforce a call from an inherited constructor to a specific base constructor?

Last Answer : Yes, just place a colon, and then keyword base (parameter list to invoke the appropriate constructor) in the overloaded constructor definition inside the inherited class.

Description : In terms of constructors, what is the difference between: public MyDerived() : base() an public MyDerived() in a child class?

Last Answer : Nothing

Description : Can base constructors can be private?

Last Answer : Yes

Description : If a base class has a number of overloaded constructors, and an inheriting class has a number of overloaded constructors; can you enforce a call from an inherited constructor to a specific base constructor?

Last Answer : Yes, just place a colon, and then keyword base (parameter list to invoke the appropriate constructor) in the overloaded constructor definition inside the inherited class.

Description : If a base class has a bunch of overloaded constructors, and an inherited class has another bunch of overloaded constructors, can you enforce a call from an inherited constructor to an arbitrary base constructor? 

Last Answer : Yes, just place a colon, and then keyword base (parameter list to invoke the appropriate constructor) in the overloaded constructor definition inside the inherited class. 

Description : C# provides a default constructor for me. I write a constructor that takes a string as a parameter, but want to keep the no parameter one. How many constructors should I write? 

Last Answer : Two. Once you write at least one constructor, C# cancels the freebie constructor, and now you have to write one yourself, even if there’s no implementation in it.

Description : Can a class or a struct have multiple constructors?

Last Answer : Yes, a class or a struct can have multiple constructors. Constructors in C# can be overloaded.

Description : Can you have parameters for static constructors?

Last Answer : No, static constructors cannot have parameters.

Description : Are constructors inherited? Can a subclass call the parent's class constructor? When?

Last Answer : Ans. You cannot inherit a constructor. That is, you cannot create a instance of a subclass using a constructor of one of it's superclasses. One of the main reasons is because ... developer the ability to override a superclasses constructor you would erode the encapsulation abilities of the language.

Description : Can constructors be synchronized in Java ?

Last Answer : Ans. No. Java doesn't allow multi thread access to object constructors so synchronization is not even needed.

Description : Explain the types of constructors in Java with suitable example.

Last Answer : Constructors are used to initialize an object as soon as it is created. Every time an object is created using the new' keyword, a constructor is invoked. If no constructor is defined in a class, java compiler creates ... of First Second Rectangle : "+ (r1.length*r1.breadth)); } }

Description : Explain parameterized constructors with example.

Last Answer : A constructor that can take arguments is known as parameterized constructor. In some applications, it may be necessary to initialize the various data members of different objects with different values when they ... as an argument. Member function put displays the value of data member m .

Description : Explain multiple constructors in a class with suitable example. 

Last Answer : Multiple constructors in a class means a class can contain more than one constructor. This is also known as constructor overloading. All constructors are defined with the same name as the class they belong to. All the ... default constructor integer(int a, int b) { m = a; n = b; cout

Description : What is Virtual Memory ?

Last Answer : The computer has physical memory or RAM attached. RAM has size limitations. When you turn on the computer, the program loads in RAM. When you open a file, it also loads in RAM. If the file ... address is called mapping. Copying a virtual page from disk to main memory is called paging or shopping.

Description : Virtual memory is 1) Memory on the hard disk that the CPU uses as an extended RAM 2) RAM 3) Only necessary if you do not have any RAM in your computer 4) A back up device for floppy disks 5) None of these

Last Answer : Answer :2

Description : Which of the following is used to hold running program instructions? a) Primary Storage b) Virtual Storage c) Internal Storage d) Minor Devices

Last Answer : Answer: a Explanation: The primary storage is responsible for holding the data, intermediate results and the results of ongoing processes or jobs. Virtual storage is the main memory storage required for saving large amount of data for future reference. The other options are invalid

Description : The two basic types of memory in a computer are ________ a) Primary and major b) Primary and Secondary c) Minor and Major d) Main and virtual

Last Answer : Answer: b Explanation: There are two types of memories in a computer system: The Primary Memory and the Secondary Memory. The primary memory can be directly accessed by the CPU whereas the secondary memory cannot be directly accessed

Description : VDU stands for __________ a) Virtual Display Unit b) Visual Display Unit c) Virtual Detection Unit d) Visual Detection Unit

Last Answer : Answer: b Explanation: A Visual Display unit is also referred to as the monitor who basically is used to give the results or outputs to the user. It comprises of a cathode ray tube internally

Description : Technique of using disk space to make programs believe that the system contains more Random Access Memory(RAM) than is actually available is called ______ A. Random Access Memory B. Primary Memory C. Secondary Memory D. Virtual Memory

Last Answer : D. Virtual Memory

Description : Technique to implement virtual memory where memory is divided into units of fixed size memory is _________ A. Paging B. De-fragments C. Segmentation D. None of the above

Last Answer : A. Paging

Description : Under virtual storage ________ A. Two or more programs are stored in primary storage B. Only active pages of a program in primary storage C. Inter-program, interference may occur D. None of the Above

Last Answer : B. Only active pages of a program in primary storage

Description : ___________ is a very high speed memory placed in between RAM and CPU. A. Magnetic disk B. Magnetic drum C. Virtual memory D. Cache memory

Last Answer : D. Cache memory

Description : Virtual memory is _________ A. an extremely large main memory B. an extremely large secondary memory C. a type of used in super computers D. an illusion of extremely large main memory

Last Answer : D. an illusion of extremely large main memory

Description : _____________is a feature of an operating system that allows a computer to compensate for shortages of physical memory by temporarily transferring pages of data from RAM to disk storage. A. Flash memory B. Virtual memory C. Buffer D. None of the Above

Last Answer : B. Virtual memory

Description : _________ is a type of non-volatile memory that erases data in units called blocks. A. Flash memory B. Virtual memory C. Buffer D. None of the Above

Last Answer : A. Flash memory

Description : _________ is the transfer of computer data from a temporary storage area to the computer’s permanent memory. A. Flash B. Virtual C. Buffer Flush D. None of the Above

Last Answer : C. Buffer Flush

Description : _________ is a data area shared by hardware devices or program processes that operate at different speeds or with different sets of priorities. A. Flash memory B. Virtual memory C. Buffer D. None of the Above

Last Answer : C. Buffer

Description : Which is an interactive device that facilitates touch sensation and fine-motion control in Robotics and Virtual reality? A. Light Pen B. Joystick C. Data Glove D. None of the Above

Last Answer : C. Data Glove

Description : In which of the following types of banking, there is a direct execution of transaction between a bank and its consumers? A. Retail Banking B. Universal Banking C. Virtual Banking D. Unit Banking E. other than those given as options

Last Answer : A. Retail Banking Explanation: Retail banking also known as Consumer Banking is the provision of services by a bank to individual consumers, rather than to companies, corporations or other ... include savings and transactional accounts, mortgages, personal loans, debit cards, and credit cards.

Description : Unified Payment System (UPI), a common platform which links your _________ to a virtual payment address, effectively making money transfer as easy as an SMS. A. Bank Account Number B. IFSC Code C. Virtual Address D. All of the Above E. None of the Above.

Last Answer : A. Bank Account Number Explanation: Unified Payment System (UPI), a common platform which links your bank account number to a virtual payment address, effectively making money transfer as easy as an SMS.

Description : Which of the following is the format of Virtual Address in UPI? A. [name] @ [bank name] B. [Phone number] @ [bank name] C. [name] @ [bank branch name] D. Both (A) and (B) E. Both (B) and (C)

Last Answer : D. Both (A) and (B) Explanation: Instead of account details, the receiver can share a virtual address, which can be your name, or your phone number and the sender can ... your phone number is 1234567890, then your virtual address could be 1234567890@axisbank or 1234567890@icicibank and so on.

Description : Customers using the UPI system only share _____ A. Bank Account Number B. IFSC Code C. Virtual Address D. All of the Above E. None of the Above.

Last Answer : C. Virtual Address Explanation: Customers using the system do not have to disclose any sensitive information such as bank account numbers or IFSC codes during a financial transaction. It is safe as the customers only share a virtual address and provide no other sensitive information.

Description : Power Point 97 incorporated the _______language , underlying all macro generation in office 97: a) Visual Basic for Applications b) Visual Basic for Software c) Virtual Base Language d) None of These

Last Answer : a) Visual Basic for Applications

Description : VBA stands for: a) Visual Basic For Application b) Virtual Based For Application c) Various Basics Application d) None of These

Last Answer : a) Visual Basic For Application

Description : VPN stands for: a) Virtual Perfect Network b) Virtual Power Network c) Virtual Private Network d) None of These

Last Answer : c) Virtual Private Network

Description : VGA stands for: a) Virtual Graphics Assessment b) Video Graphics Array c) Various Graphics Arrays d) None of These

Last Answer : b) Video Graphics Array

Description : VGA stands for: a) Virtual Graphics Adapter b) Video Graphics Adapter c) Various Graphics Adapter d) None of These

Last Answer : b) Video Graphics Adapter

Description : VDU stands for: a) Virtual Display Unit b) Video Display Unit c) Visual Display Unit d) None of These

Last Answer : c) Visual Display Unit

Description : JVM stands for: a) Java Via Mechanism b) Justify Virtual Method c) Jumbo Verbose Mechanism d) Java Virtual Machine e) None of These

Last Answer : d) Java Virtual Machine

Description : Virtual Memory is: a) An extremely large main memory b) An extremely large secondary memory. c) An illusion of an extremely large memory. d) None of The Above

Last Answer : c) An illusion of an extremely large memory.

Description : VIRUS stands for 1) Very Important Resource Under Search 2) Virtual Information Resource Under Resize 3) Verify Interchange Result Until Source 4) Very Important Record User Searched

Last Answer : 2) Virtual Information Resource Under Resize

Description : What is meant by a Virtual Classroom?

Last Answer : In a virtual classroom, the teacher deliver lecture at its own workplace while the students, connected to a network, may listen to him at their homes. They may put questions and answers are sent to them via email.

Description : VIRUS stands for 1 Very Important Resource Under Search 2 Virtual Information Resource Under Resize 3 Verify Interchange Result Until Source 4 Very Important Record User Searched

Last Answer : 2 Virtual Information Resource Under Resize

Description : What do you mean by pure virtual functions?

Last Answer : A pure virtual member function is a member function that the base class forces derived classes to provide. Normally these member functions have no implementation. Pure virtual functions are equated to zero. class Shape { public: virtual void draw() = 0; };

Description : What are virtual functions?

Last Answer : A virtual function allows derived classes to replace the implementation provided by the base class. The compiler makes sure the replacement is always called whenever the object in question is actually of the ... be replaced in the derived class, even if users don't know about the derived class.