OOPS Concept
OOPS CONCEPT
- Class – group of data members & member functions
- Like person can be class having data members heightand weight and member functions as get_details() and put_details() to manipulate on details
- Class is nothing until you create it’s object
- Object – instantiates class allocates memory
OOPS Fundamentals…
Access to data members & member functions can be
done using object only (if they are not static!)
OOPS features are:
1. Encapsulation
2. Data hiding
3. Data reusability
4. Overloading (polymorphism)
5. Overriding
OOPS Features…
- Encapsulation – making one group of data members & member functions
- Can be done through class
- Then group of data members & Member functions will
- be available just by creating object.
- Data Hiding – can be done through access modifiers
- Access modifiers are private, public, protected and internal
- Private members or member function won’t be available outside class
- Public – available all over in program outside class also
- rotected – members that are available in class as well as in it’s child class
- Private for another class
- Protected access modifier comes only when inheritance is in picture
- Internal is used with assembly creation
EXAMPLE :
class employee //Class Declaration
{
private:
char empname[50];
int empno;
public:
void getvalue() {
cout<<"INPUT Employee Name:";
cin>>empname;
cout<<"INPUT Employee Number:";
cin>>empno; }
void displayvalue() {
cout<<"Employee Name:"<<empname<<endl;
cout<<"Employee Number:"<<empno<<endl; }
};
main()
{
employee e1; //Creation of Object
e1.getvalue();
e1.displayvalue();
}
OOPS Fundamentals…
Access to data members & member functions can be
done using object only (if they are not static!)
OOPS features are:
1. Encapsulation
2. Data hiding
3. Data reusability
4. Overloading (polymorphism)
5. Overriding
OOPS Features…
- Encapsulation – making one group of data members & member functions
- Can be done through class
- Then group of data members & Member functions will
- be available just by creating object.
- Data Hiding – can be done through access modifiers
- Access modifiers are private, public, protected and internal
- Private members or member function won’t be available outside class
- Public – available all over in program outside class also
- rotected – members that are available in class as well as in it’s child class
- Private for another class
- Protected access modifier comes only when inheritance is in picture
- Internal is used with assembly creation
EXAMPLE :
class employee //Class Declaration
{
private:
char empname[50];
int empno;
public:
void getvalue() {
cout<<"INPUT Employee Name:";
cin>>empname;
cout<<"INPUT Employee Number:";
cin>>empno; }
void displayvalue() {
cout<<"Employee Name:"<<empname<<endl;
cout<<"Employee Number:"<<empno<<endl; }
};
main()
{
employee e1; //Creation of Object
e1.getvalue();
e1.displayvalue();
}