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                      
tip   To Refer this Site to Your Friends   Click Here
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
How to avoid a class from instantiation?
 Question Submitted By :: Shalini
I also faced this Question!!     Rank Answer Posted By  
 
  Re: How to avoid a class from instantiation?
Answer
# 1
Have a Pure Virtual function in the class. This will not 
allow to create an object of the class and hence cannot be 
instatiated. But its a different thing to inherit the class 
and give definition to Pure Virtual function, But the class 
alone cannot be instantiated.The class hence,is also called 
Abstract Base class.
 
Is This Answer Correct ?    3 Yes 0 No
Vinay Bondade
 
  Re: How to avoid a class from instantiation?
Answer
# 2
We can aviod a class from instantiation by making all 
variants of constructors as private. We can provide user 
defined function like create member function under public 
scope  and call this private construcotrs from this create 
function to create an object for that class.
 
Is This Answer Correct ?    1 Yes 2 No
Ravi
 
 
 
  Re: How to avoid a class from instantiation?
Answer
# 3
Yes, I agree with Ravi. Classes can be prevented from 
instantiating and also from getting inherited using provate 
constructors. The initialisation can be done using member 
functions in which case it is called "clone" functions(I 
hope so, Pls correct me if i'm wrong!).
 
Is This Answer Correct ?    0 Yes 1 No
Rsn
 
  Re: How to avoid a class from instantiation?
Answer
# 4
Make an abstract class.abstract class cant b intialized.
I think so....
 
Is This Answer Correct ?    0 Yes 0 No
Sanish Joseph
 
  Re: How to avoid a class from instantiation?
Answer
# 5
make the class Abstract it will not be instantiated 
and the pure virtual function is used to avoid the base call
function to be get called if we make a function as virtual
only a derived class function will get called
 
Is This Answer Correct ?    0 Yes 0 No
Chandrakant
 

 
 
 
Other C++ General Interview Questions
 
  Question Asked @ Answers
 
What about Virtual Destructor? Virtusa1
what is the diff b/n c and c++ a. dynamic scoping b. nested switching c. declaration of variables in any code block d. separation of compilation and linking Hughes1
What are the advantages and disadvantages of using inline and const? TCS1
Explain the ISA and HASA class relationships. How would you implement each in a class design?  2
What is "map" in STL?  1
Describe functional overloading? HP3
Can inline functions have a recursion? Give the reason?  1
Implement strcmp Citadel2
What are Virtual Functions? How to implement virtual functions in "C" ?  2
Explain working of printf?  3
When volatile can be used? Symphony2
Is there any difference between dlearations int* x and int *x? If so tell me the difference? Lason13
class basex { int x; public: void setx(int y) {x=y;} }; class derived : basex {}; What is the access level for the member function "setx" in the class "derived" above? a) private b) local c) global d) public e) protected Quark1
Write a function which takes a character array as input and reverses it in place. Lehman-Brothers2
What is the Maximum Size that an Array can hold? Satyam31
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
What is the use of static functions? Symphony6
why can't we declare data member of class auto register or extern  1
What are inline functions? Verizon2
If P is the population on the first day of the year, B is the birth rate, and D is the death rate, the estimated population at the end of the year is given by the formula: The population growth rate is given by the formula: B – D Write a program that prompts the user to enter the starting population, birth and death rates, and n, the number of years. The program should then calculate and print the estimated population after n years. Your program must have at least the following functions: 1. growthRate: This function takes its parameters the birth and death rates, and it returns the population growth rate. 2. estimatedPopulation: This function takes its parameters the current population, population growth rate, and n, the number of years. It returns the estimated population after n years Your program should not accept a negative birth rate, negative death rate, or a population less than 2.  1
 
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