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
Define a pdb file.
What are static member functions?
Write about an iterator class?
Draw a flow chart and write a program for the difference between the sum of elements with odd and even numbers. Two dimensional array.
What is the difference between mutex and binary semaphore?
Can you write a function similar to printf()?
What is a character in c++?
What is the difference between containment and delegation?
What is runtime errors c++?
What is a list c++?
Difference between pointer to constant vs. Pointer constant
What is srand c++?
Incase of a function declaration, what is extern means?
What is using namespace std in cpp?
declare an array of structure where the members of the structure are integer variable float variable integer array char variable access all elements of the structure using dot operator and this pointer operator