ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Do you have a collection of Interview Questions and interested to share with us!!
Please send that collection to along with your userid / name. ThanQ
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C++  >>  C++ General
 
 


 

 
 STL interview questions  STL Interview Questions
 OOPS interview questions  OOPS Interview Questions
 C++ General interview questions  C++ General Interview Questions
Question
Do we have private destructors?
 Question Submitted By :: Shalini
I also faced this Question!!     Rank Answer Posted By  
 
  Re: Do we have private destructors?
Answer
# 1
No we cannot have private destructors and private 
constructors.........
 
Is This Answer Correct ?    2 Yes 1 No
Jack
 
  Re: Do we have private destructors?
Answer
# 2
we cannot say it destructors are not private. because for
empty class if we use delete operator then it is going to
delete the destructor which is private.
 
Is This Answer Correct ?    0 Yes 1 No
Vishwa
 
 
 
  Re: Do we have private destructors?
Answer
# 3
RE: #1

You can have private constructors. It's pretty common
practice when you create a class which you want to never be
constructed with "new" from outside the class (for example,
if you have a static factory member of the class).
 
Is This Answer Correct ?    1 Yes 1 No
Guest
 
  Re: Do we have private destructors?
Answer
# 4
In replay to Vishwa,

for empty class, compiler will supply a default constructor 
and a destructor for us, their access modifiers were public.
 
Is This Answer Correct ?    0 Yes 1 No
Thuang
 
  Re: Do we have private destructors?
Answer
# 5
No we can not have private destructor
 
Is This Answer Correct ?    0 Yes 1 No
Deepak
 
  Re: Do we have private destructors?
Answer
# 6
no we do not have private destructors because the 
destructors can be declared only in public access 
specifier.
 
Is This Answer Correct ?    0 Yes 1 No
Pooja
 
  Re: Do we have private destructors?
Answer
# 7
We can have Private Destructor and by using Friend Function
we can also instantiate it. :)
 
Is This Answer Correct ?    1 Yes 0 No
Vaibhav Meena
 
  Re: Do we have private destructors?
Answer
# 8
U can't instantiate instance of that class.
 
Is This Answer Correct ?    0 Yes 1 No
Shakti Singh Khinchi
 
  Re: Do we have private destructors?
Answer
# 9
yes, we can have both private constructor and destructor 
and can use them with help of static function for example

class Base
{
static int i;
Base(){}
~Base(){}
public:
static Base *Creat_Object();
static void Destroy_Object(Base *p);
void Add()
{
cout<<i<<" Add function"<<endl;
}
};

int Base::i=0;
Base* Base::Creat_Object()
{
Base * ptr = new Base();
i=5;
return ptr;
}

void Base::Destroy_Object(Base *p)
{
delete p;
}

void main()
{
Base *temp = Base::Creat_Object();
temp->Add();
Base::Destroy_Object(temp);
}

correct me if i am wrong.
 
Is This Answer Correct ?    2 Yes 0 No
Sampurna Pandey
 

 
 
 
Other C++ General Interview Questions
 
  Question Asked @ Answers
 
What compiler was used? Intel3
1)#include <iostream.h> int main() { int *a, *savea, i; savea = a = (int *) malloc(4 * sizeof(int)); for (i=0; i<4; i++) *a++ = 10 * i; for (i=0; i<4; i++) { printf("%d\n", *savea); savea += sizeof(int); } return 0; } 2)#include <iostream.h> int main() { int *a, *savea, i; savea = a = (int *) malloc(4 * sizeof(int)); for (i=0; i<4; i++) *a++ = 10 * i; for (i=0; i<4; i++) { printf("%d\n", *savea); savea ++; } return 0; } The output of this two programs will be different why?  2
what is data Abstraction? and give example TCS13
what is pulse code modulation? Wipro1
Give 2 examples of a code optimization?  1
what is meaning of isa and hsa  1
What are the different types of Storage classes?  3
Do we have private destructors? Symphony9
What is Name Decoration? Lucent2
In a class, there is a reference or pointer of an object of another class embedded, and the memory is either allocated or assigned to the new object created for this class. In the constructor, parameters are passed to initialize the data members and the embedded object reference to get inialized. What measures or design change should be advised for proper destruction and avioding memory leaks, getting pointers dangling for the embedded object memory allocation? Please suggest. GE3
whats the size of class EXP on 32 bit processor? class EXP { char c1; char c2; int i1; int i2; char *ptr; static int mem; }; Huawei4
What are the differences between public, private, and protected access? Wipro4
Implement strncpy  2
How can you find the nodes with repetetive data in a linked list? Lucent1
difference between c and c++? Infosys8
implement stack using stack.h headerfile functions Subex1
What is the output of: String a1 = "Hello"; String a2 = "world!"; String* s1 = &a2; String& s2 = a1; s1 = &a1; s2 = a2; std::cout << *s1 << " " << s2 << std::endl; Lehman-Brothers4
const char * char * const What is the differnce between the above two? TCS8
Write a String class which has: 1) default constructor 2) copy constructor 3) destructor 4) equality operator similar to strcmp 5) constructor which takes a character array parameter 6) stream << operator Lehman-Brothers1
catch(exception &e) { . . . } Referring to the sample code above, which one of the following lines of code produces a written description of the type of exception that "e" refers to? a) cout << e.type(); b) cout << e.name(); c) cout << typeid(e).name(); d) cout << e.what(); e) cout << e; Quark2
 
For more C++ General Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com