1. Encapsulation:
Encapsulation is the mechanism that binds together code and the data it manipulates ,and keeps both safe from outside interface and misuse..
the Data members and the member functions that are binded together in a block act as a fixed block and no data member or member function outside the class can access the members of class unless it has the rights to access them..
class Encap
{
void sum()
{
int a,b,c;
a=10;
a=10;
b=20;
c=a+b;
System.out.print("Sum is"+c);
}
}
Only the objects of this class can access these functions and data members.
2. Inheritance:
Inheritance means one class inherits the features of some other class. The member functions are not again written in to the derived class but the member functions of base class are directly copied into the derived class. The objects of derived class can access the member functions of base class.
Base class is also known as parent class and the derived class is also known as child class.
Following are two main types of inheritance.
3. Polymorphism
Polymorphism allows one interface to be used for a general class of actions. Polymorphism in simple means"ability to take more than one form" , means you can use different functions with same name to perform different task, the functions may need to have different number of arguments, on the basis of number of arguments passed it is decided that which same of same name is to be executed.