Различие между абстракцией — инкапсуляция и полиморфизм — перегрузка

Я читаю разные статьи по этим терминологиям, но не могу понять фактическую разницу между этими терминологиями. Мне нужен реальный пример, например пример кода, чтобы понять, как работает абстракция и инкапсуляция.
Кто-то также, пожалуйста, скажите мне разницу между полиморфизмом и перегрузкой. Помощь будет высоко ценится.

0

Решение

Здравствуйте, вы можете попробовать прочитать это, может быть, это поможет:

 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.
3

Другие решения

Перейдите по этой ссылке, надеюсь, это поможет вам
разница между полиморфизмом и перегрузкой перегрузка

0

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector