I am reading different articles on these terminologies but I am unable to understand actual difference between these terminologies. I need some real example e.g some code example, to understand how abstraction and encapsulation works. Somebody also please tell me the difference between polymorphism and overloading. Help would be highly appreciated.
Asked
Active
Viewed 90 times
1 Answers
2
Hi there you may try to read this maybe it will help:
Short answer:
They are the same.
Long Answer, (and yet less revealing):
Polymorphism is simply the ability to have many different methods (Or functions,
for those who are used to C-Type programs) to have the same name but act differently
depending on the type of parameters that were passed to the function.
So for example, we may have a method called punch, which accepts no parameters at
all,
and returns an integer:
public int punch()
{
return 3;
}
We could also have a method named punch that accepts a String and returns a
boolean.
public boolean punch(String poorGuyGettingPunched)
{
if(poorGuyGettingPunched.equals("joe"))
{
System.out.println("sorry Joe");
return true;
}
else
return false;
}
That is called polymorphism... And strangely enough, it is also called overloading.

Asiya Fatima
- 1,388
- 1
- 10
- 20