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
Write a program that takes a 5 digit number and calculates 2 power that number and prints it.
List the special characteristics of constructor.
What is lambda expression c++?
What is the output of the following program? Why?
What does flush do c++?
What is wrapper class in c++?
We use library functions in the program, in what form they are provided to the program?
When do you call copy constructors?
If I is an integer variable, which is faster ++i or i++?
What is c++ coding?
How to defines the function in c++?
what are Access specifiers in C++ class? What are the types?
What do you mean by a template?
What is size_type?
Can recursive program be written in C++?