plzzzzzz don't give any theoretical answer.. | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
0

plzzzzzz don't give any theoretical answer..

what is the need of inerface ? i don't want theoretical answer but programming

15th Jul 2017, 6:23 AM
Somnath Ghosh
Somnath Ghosh - avatar
2 ответов
+ 4
Example: class Animal{ int size; // and other things generic to all animals } interface Pettable{ // relevant to some but not all animals // include specific pettable behaviours } class Cat extends Animal implements Pettable{ // cat specific things } class Lion extends Animal{ //wouldn't want to pet a Lion // lion specific things } https://code.sololearn.com/cvC4yLbL85Ao/#java Explanation: An interface describes properties that can be reused by other classes. Since a class can only subclass one other class, but can implement many interfaces, this gives you a way to reuse common behaviours. Explanation of the example: Let's say you have a class Animal, which is extended by different types of animals like Cat, Dog, Lion, Hippo, etc. All animals would have a size, food, etc. which they could inherit from Animal class. But not all animals are domesticated or are "Pettable" so this could be an interface implemented only by certain animals (the dog and cat, not the lion).
16th Jul 2017, 7:02 AM
marit vandijk
0
little bit advance
15th Jul 2017, 6:49 AM
Somnath Ghosh
Somnath Ghosh - avatar