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
Explain the different access specifiers for the class member in c++.
How many standards of c++ are there?
What is meant by the term name mangling in c++?
What is oop in c++?
Is facebook written in c++?
What is a set in c++?
Why c++ is the best language?
Is c++ a float?
Is it possible for a member function to use delete this?
When one must use recursion function? Mention what happens when recursion functions are declared inline?
What is an overflow error?
Write a program which is required to process the time of a clock in hours and minutes, entered from the keyboard. With this program, there are two requirements for any data entered by a user: 1. The data must be of the correct type (in this case, two ints). 2. The data must be in the correct range: this means that, for the minutes, negative numbers and any number above 59 must be rejected; for the hours, negative numbers and any number above 23 must be rejected. Output error message for invalid data input. Output the time one and a half hour after the time input. i.e. Hour: 22 Min: 32 One and a half hour after 22:32 is 00:02
Describe protected access specifiers?
What is a template in c++?
Keyword mean in declaration?