GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Interview Questions  >  Programming  >  C++

 Print  |  
Question:  Inheritance

Answer: Which one of the following statements regarding C++ class inheritance is FALSE?

a. Inheritance promotes generic design and code reuse.
b. Struct cannot be inherited in C++.
c. C++ supports multiple inheritance.
d. Inheritance is a mechanism through which a subclass inherits the properties and behavior of its superclass.

 


June 06, 2009 15:28:10 #2
 desirocks   Member Since: May 2009    Total Comments: 1 

RE: Inheritance
 
Structures can be inherited.  They are almost similar to classes in C++.  The only difference is that the default access specifier in struct is public while it is private in a class. 

Now I wanted to mention what I observed.  You can inherit a class in a structure but you cannot inherit a structure inside a class.  You may want to try this out.  Because I tried it out.

class A
{
   public:
       A()
       {
           cout<<"IN A";
       }
      int a;
};

struct B : public A //This will work
{
 
};

struct C
{
      //int c;
}

class D: public C //This won't work
{   
   
};

int main()
{
  
   D d;
    A abc;
    B bad;
   B.a = 1;
   D.c = 2;    //This would not work
    system("PAUSE");
   return 0;
}
     

 

Back To Question