GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  C++
Go To First  |  Previous Question  |  Next Question 
 C++  |  Question 200 of 203    Print  
Inheritance
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.

 



  
Total Answers and Comments: 9 Last Update: September 25, 2009     Asked by: desirocks 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: wsxzaq
 
Struct cannot be inherited in C++

Above answer was rated as good by the following members:
parul.misra, anchal.chawla, AlexeyP, MercurySystemsEngineering
June 04, 2009 06:49:05   #1  
wsxzaq Member Since: June 2009   Contribution: 1    

RE: Inheritance
Struct cannot be inherited in C++
 
Is this answer useful? Yes | NoAnswer is useful 2   Answer is not useful 1Overall Rating: +1    
June 10, 2009 15:28:10   #2  
desirocks Member Since: May 2009   Contribution: 3    

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;
}

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 1Overall Rating: -N/A-    
June 12, 2009 08:08:17   #3  
gunjan.chandra Member Since: April 2009   Contribution: 7    

RE: Inheritance
B. Structures cannot be inherited in C++ is False
There are some major difference between Class and Structures in C++.
1. Class members are private by default but in Stuctures they are Public.
2. In case of Structures we cannot initialize variables during declaration while in Class we can.
3. Structures does not support polymorphism while Classes do.

 
Is this answer useful? Yes | No
June 13, 2009 00:56:37   #4  
tewari2312 Member Since: June 2009   Contribution: 4    

RE: Inheritance
b. is False

Struct can be inherited in C++.

Other 3 options are true.

 
Is this answer useful? Yes | No
June 19, 2009 01:52:13   #5  
nivi.babuji Member Since: June 2009   Contribution: 3    

RE: Inheritance
The statement regarding structure is false because structures are generally inheritable.
 
Is this answer useful? Yes | No
June 26, 2009 09:33:10   #6  
rameshvar Member Since: June 2009   Contribution: 1    

RE: Inheritance
a. Inheritance promotes generic design and code reuse.
 
Is this answer useful? Yes | No
July 20, 2009 10:40:13   #7  
rajangidwani Member Since: July 2009   Contribution: 5    

RE: Inheritance
Struct cannot be inherited in C++.
 
Is this answer useful? Yes | No
July 29, 2009 09:25:27   #8  
yzesong Member Since: July 2009   Contribution: 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;
}

 
Is this answer useful? Yes | No
September 23, 2009 12:52:10   #9  
Master Sargent Member Since: September 2009   Contribution: 1    

RE: Inheritance

The only difference between a class and a struct is a class has private access and private inheritance by default and a struct has public access and public inheritance by default. The only place I'm aware of that you can't replace class with struct is in a template definition. For example template where you can also use template but template is incorrect.


struct is a class keyword and anything you can do with a class you can do with struct. Virtual functions pure virtual functions inheritance data member initialization all of it there aren't any restrictions. You could literally go through a program and replace every instance of class except as noted previously with the equivalent struct definition.



 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape