Basics of C
Basics of C
Basics of C
About c++oop:
By now, you are quite familiar with the public keyword that
appears in all of our class examples:
Example
class MyClass { // The class
public: // Access specifier
// class members goes here
};
However, what if we want members to be
private and hidden from the outside world?
In C++, there are three access specifiers:
Example:
class MyClass {
public: // Public access specifier
int x; // Public attribute
private: // Private access specifier
int y; // Private attribute
};
int main() {
MyClass myObj;
myObj.x = 25; // Allowed (public)
myObj.y = 50; // Not allowed (private)
return 0;
}
Encapsulation
In object oriented programming, encapsulation is the
concept of wrapping together of data and information
in a single unit. A formale defination of encapsulation
would be: encapsulation is binding togather the data
and related function that can manipulate the data.
Polymorphism
The name defines polymorphism is multiple forms.
which means polymorphism is the ability of object
oriented programming to do some work using multiple
forms. The behaviour of the method is dependent on
the type or the situation in which the method is called.
Let’s take a real life example, A person can have more
than one behaviour depending upon the situation. like
a woman a mother, manager and a daughterAnd this
define her behaviour. This is from where the concept
of polymorphism came from.
In c++ programming language, polymorphism is
achieved using two ways. They are operator overloading
and function overloading.
// Derived class
class Car: public Vehicle {
public:
string model = “Ford";
};
int main() {
Car myCar;
myCar.honk();
cout << myCar.brand + " " + myCar.model;
return 0;
}
Arrays in c++
Array
int main()
{
// Array declaration by specifying size and
initializing
// elements
int arr[6] = { 10, 20, 30, 40 };
return 0;
}
Thanku