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
Is rust better than c++?
What does the linker do?
What would happen on forgetting [], while deallocating an array through new?
Do you know about latest advancements in C++ ?
What causes a runtime error c++?
What are put and get pointers?
What is the type of this pointer in c++?
What is srand c++?
Discuss the effects occur, after an exception thrown by a member function is unspecified by an exception specification?
Is ca high or low level language?
Show the declaration for a static member variable.
What are the various arithmetic operators in c++?
When does a 'this' pointer get created?
What do you mean by vtable and vptr in c++?
What's the order in which the local objects are destructed?