B.TECH CSE BT ECE(oop's)- Abstract class
Abstract class in C++ is the one which is not used to create objects.
These type of classes are designed only to treat like a base class (to
be inherited by other classes). It is a designed technique for program
development which allows making a base upon which other classes may be
built.
In C++ language, programmers can use access modifiers to define the abstract interface of the class. A C++ class may contain zero or more access labels:
Here is an example of declaring Public members of C++ class:
In C++ language, programmers can use access modifiers to define the abstract interface of the class. A C++ class may contain zero or more access labels:
- As you all became familiar that members defined within the public access specifier are accessible to l parts of the program. The data abstraction of a type can be viewed or classified by its public members.
- When the access specifier is in private mode, members defined in the private mode are not accessible to code that uses the class. The private section is designed specifically for hiding the implementation of code within a C++ program.
Here is an example of declaring Public members of C++ class:
#include <iostream>
using namespace std;
class sample {
public:
int gl, g2;
public:
void val()
{
cout << "Enter Two values : "; cin >> gl >> g2;
}
void display()
{
cout << gl << " " << g2;
cout << endl;
}
};
int main()
{
sample S;
S.val();
S.display();
}
Enter Two values : 20 50 20 50Here is a Private member example in which member data cannot be accessed outside the class:
#include <iostream>
using namespace std;
class sample {
public:
int gl, g2;
public:
void val()
{
cout << "Enter Two values : "; cin >> gl >> g2;
}
private:
void display()
{
cout << gl << " " << g2;
cout << endl;
}
};
int main()
{
sample S;
S.val();
S.display();
}
If you execute the
above program, the private member function will not be accessible and
hence the following error message will appear like this in some
compiler: error: 'void sample::display()' is private void display() ^
- Class internals get protected from inadvertent user-level errors
- Programmer does not have to write the low-level code
- Code duplication is avoided and so programmer does not have to go over again and again fairly common tasks every time to perform similar operation
- The main idea of abstraction is code reuse and proper partitioning across classes
- For small projects, this may not seem useful but for large projects, it provides conformity and structure as it provides documentation through the abstract class contract
- It allows internal implementation details to be changed without affecting the users of the abstraction
Excellent blog. Looking for software courses?
ReplyDeleteLoadrunner Training in Chennai
JAVA Training in Chennai
Hadoop Training in Chennai
Selenium Training in Chennai
German Classes in chennai
PHP Training in Chennai
php course
Thank you so much for this post. It will be a great help for us.
ReplyDeleteR Programming training Center in Delhi
/NCR
Nice way of expressing your ideas with us.thanks for sharing with us and please add more information's.
ReplyDeleteJAVA Training in Chennai
JAVA Training in Tnagar
Selenium Training in Chennai
Digital Marketing Course in Chennai
Python Training in Chennai
Big data training in chennai
JAVA training in Annanagar
Java courses in chennai anna nagar
"wow
ReplyDeleteDigital Marketing Training Course in Chennai | Digital Marketing Training Course in Anna Nagar | Digital Marketing Training Course in OMR | Digital Marketing Training Course in Porur | Digital Marketing Training Course in Tambaram | Digital Marketing Training Course in Velachery"