Sample Questions Best site for GRE, LSAT, SAT, GMAT, TOEFL, CCNA, CCSA and interview sample questions  

Technical Sample Questions : C |  C++ |  Oracle |  Java | Unix |  Operating Systems |  Data Structure

Sample Technical Questions

C++ and OOPS Sample Question

  1. class some{
    		cout«"some's destructor"«endl;
    void main()
    	some s;

    Answer :

    some's destructor
    some's destructor


    Destructors can be called explicitly. Here 's.~some()' explicitly calls the destructor of 's'. When main() returns, destructor of s is called again, hence the result.
  2. #include ‹iostream.h›
    class fig2d
    	int dim1;
    	int dim2;
    	fig2d() { dim1=5; dim2=6;}
    	virtual void operator«(ostream & rhs);
    void fig2d::operator«(ostream &rhs)
    	rhs «this->dim1«" "«this->dim2«" ";
    /*class fig3d : public fig2d
    	int dim3;
    	fig3d() { dim3=7;}
    	virtual void operator«(ostream &rhs);
    void fig3d::operator«(ostream &rhs)
    	fig2d::operator «(rhs);
    	rhs«this -> dim3;
    void main()
    	fig2d obj1;
    //	fig3d obj2;
    	obj1 « cout;
    //	obj2 « cout;

    Answer :

    5 6


    In this program, the « operator is overloaded with ostream as argument. This enables the 'cout' to be present at the right-hand-side. Normally, 'cout' is implemented as global function, but it doesn't mean that 'cout' is not possible to be overloaded as member function.
    Overloading « as virtual member function becomes handy when the class in which it is overloaded is inherited, and this becomes available to be overrided. This is as opposed to global friend functions, where friend's are not inherited.
  3. class opOverload{
    	bool operator==(opOverload temp);
    bool opOverload::operator==(opOverload temp){
    	if(*this  == temp ){
    		cout«"The both are same objects\n";
    		return true;
    		cout«"The both are different\n";
    		return false;
    void main(){
    	opOverload a1, a2;
    	a1= =a2;

    Answer :

    Runtime Error: Stack Overflow


    Just like normal functions, operator functions can be called recursively. This program just illustrates that point, by calling the operator == function recursively, leading to an infinite loop.

    « Previous || Next »

    C++ Sample Question number : 1-3 | 4-7 | 8-10 | 11-13 | 14-21 | 22-28 | 29-35 | 36-42 | 43-49 | 50-54 | 55-58 | 59-66 | 67-73 | 74-80
Sample Test Questions
GRE Sample Questions
CAT Sample Questions
GMAT Sample Questions
TOEFL Sample Questions
ACT Sample Questions
SAT Sample Questions
LSAT Sample Questions
PSAT Sample Questions
MCAT Sample Questions
PMP Sample Questions
GED Sample Questions
ECDL Sample Questions
DMV Sample Questions
CCNA Sample Questions
MCSE Sample Questions
Network+ Sample Questions
A+ Sample Questions
Technical Sample Questions
WASL Sample Questions
CISA Sample Questions

Other Sample Questions
Sample Interview Questions
Sample Teacher Interview Questions
Sample Citizenship Questions
Accuplacer Sample Questions
Science Bowl sample Questions
Driving Test Sample Questions
Sample Survey Questions Sample Essay Questions
Sample Behavioral Interview Questions

Copyright © 2004-2013, Best BSQ. All Rights Reserved.