+ 1
Abstract / Interface
Can someone explain me, when should i use abstract / interface ? abstract and interface are use for implent method on drived class right? I'm still cnfuse when should i use abstract / interface.
5 Answers
+ 5
Interfaces are used when we want unrelated classes to implement a set of methods in common, usually in different ways. For example, a radio control allows a limited number of operations: changing stations, adjusting volume ... So different radios can implement different controls (interfaces) in different ways. When implementing the interface you can not tell what to do, but how to do it. The interface specifies what operations the radio should do but not specify how to do it, it will be done according to each radio that implements the interface.
public interface Radio{
void adjusteVolume();
}
public class SamsumgRadio implements Radio{
.
.
@Override
public void adjusteVolume(){
.
.
way the Samsung radio adjusts the volume
}
}
public class LGRadio implements Radio{
.
.
.
@Override
public void adjusteVolume(){
.
.
way the LG radio adjusts the volume
}
}
+ 4
https://www.sololearn.com/Discuss/816151/?ref=app
https://www.sololearn.com/Discuss/837263/?ref=app
https://www.sololearn.com/Discuss/852906/?ref=app
https://www.sololearn.com/Discuss/719564/?ref=app
https://www.sololearn.com/Discuss/826495/?ref=app
https://www.sololearn.com/Discuss/715710/?ref=app
https://www.sololearn.com/Discuss/795776/?ref=app
https://www.sololearn.com/Discuss/783276/?ref=app
https://www.sololearn.com/Discuss/580251/?ref=app
https://www.sololearn.com/Discuss/676067/?ref=app
https://www.sololearn.com/Discuss/724205/?ref=app
+ 2
but I explained when they were used and @Kavya also explained. The links above also explains."Interfaces are used when we want...." read again bro
0
If you want to use multiple inheritance use interface , because you cannot extend two abstract classes at same time. With interfaces you have ability to do it.
0
actually i know what is interface, Sorry.. my question is when should i use between intrface and abstract?