0

I am a beginner programmer, learning Java and had a question, (I have seen many answers to this, and they seem to describe something different to what I want).

As far as I understand it, an interface is a thing, and you can have a class implement the thing, what that means is the class has to define the methods mentioned in the thing. So why not just define the methods anyway?

Iexist
  • 53
  • 1
  • 7
  • What if you have different logics, for different methods, eg: add(Object, Object), I can take anything as parameter(Not good to practice), over wholenumbers add will perform addition, over String, add will concatenate. Still the name remains same.. – peaceUser Jul 04 '16 at 11:44
  • An interface is not so much a 'thing' but more an 'aspect of a thing'. For example Serializable, Runnable, Closable. it defines a coherent API (set of methods) that might just be a small part of what a class can do. Interfaces are actually what makes Object-Orientation tick, much more so than straight subclassing (of the type Cow <- Mammal). – Adriaan Koster Jul 04 '16 at 11:48

0 Answers0