0
abstract classes and interfaces, what are the benefits of each one ?
when to use an abstract class instead of an interface and vice versa ? do i need to write 'abstract' in front of methods in abstract classes ? what's the point of making a method abstract in an abstract class ?
2 Respostas
+ 19
1 . For example, suppose you have a mobile phone and every phone has the facility of camera and phone calling and photos.
But companies of all phones are different, for example Samsung iPhone oppo ext.
So you will create an abstract method inside the abstract Class and give it your company name.
2. Yes its compelsory
3 . The third answer is the first.
+ 11
• Abstract Classes Vs Interfaces In Java:
https://codeprime.org/java-tutorials/abstraction-in-java/abstract-classes-vs-interfaces-in-java/
• An abstract class is like a class, but differs in that it only defines "generic" methods in the class, but does not actually implement them.
• An interface is a device that is used to allow unrelated objects to interact with one another, by implementing an agreed upon system of behavior. When a class implements an interface, the class agrees to implement all of the methods defined in the interface. Interfaces are useful since they capture similiarity between unrelated objects without forcing a class relationship.