Could anyone explain to me the use of an abstract class and why I would prefer them over an interface?
As far as I understand, both contain empty method declarations, except that you can implement the interface while you can't implement an abstract class, so what's the use?
Re: Abstract Classes?
1Interface is the concept of encapsulation
– The implementation can change without affecting the caller of the interface
– The caller does not need the implementation at the compile time
● It needs only the interface at the compile time
● During runtime, actual object instance is associated with the interface type
– Class Line and class MyInteger
● They are not related through inheritance
● You want both to implement comparison methods
– checkIsGreater(Object x, Object y)
– checkIsLess(Object x, Object y)
– checkIsEqual(Object x, Object y)
– Define Comparison interface which has the three abstract methods above
3. A class can implement multiple interfaces while it can extend only one class