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.

 


July 07, 2009 09:25:27 #8
 yzesong   Member Since: July 2009    Total Comments: 20 

RE: Inheritance
 
C++ struct can not be inherited is FALSE. Here is what I coded:
struct A{int a;
void print(void) {
cout << "Hello from struct A: a = " << a << endl;
};
};

class B: public A{
public:
B(int arg1, int arg2) { b = arg1; a = arg2;};
int b;
void printA(void) {
cout << "Hello from Class B: b = " << b << " ;; a = " << a << endl;
};
};

int main(int argc, char* argv[]) {
   A a;
  a.a = 10;
  a.print();

  B* b = new B(20, 30);
  b->printA();
  return 0;
}
     

 

Back To Question