What is the difference between Class and Structure?
Answer Posted / aashu gupta
There are only and only 2 differences between structure and class :
1. By default members are public in structures and private in class
2. Default inheritance in structure is public and private in class
you can verify the above differences by executing following code:
#include<iostream>
//code compiles and executes correctly means that //inheritance and polymorphism is allowed in structu
//res
using namespace std;
struct Base
{
int A;
virtual void display()=0; //polymorphism is allowed in structure
};
struct Derived:Base //public in struct and private in class
{
int B;
void display();
};
void Derived::display()
{
cout<<endl<<"A = "<<A<<endl;
}
int main()
{
Derived D;
D.A = 111;
D.display();
getchar();
return 0;
}
////////////////////////////////////////////////
Is This Answer Correct ? | 5 Yes | 1 No |
Post New Answer View All Answers
Why do we use double in c++?
Why null pointer is used?
What is an undefined reference/unresolved external symbol error and how do I fix it?
What is a namespace in c++?
What is ios in c++?
What are the advantages of c++ over c?
what kind of projects are suitable for c and c++
Function can be overloaded based on the parameter which is a value or a reference. Explain if the statement is true.
What is the difference between struct and class?
What are the effects after calling the delete this operator ?
Out of fgets() and gets() which function is safe to use and why?
Differentiate between an external iterator and an internal iterator?
Define token in c++.
What is data types c++?
What is the type of 'this' pointer?