A friend and I are studying Java. We were looking at interfaces today and we got into a bit of an discussion about how interfaces are used. The example code my friend showed me contained this: Where IVehicle is an interface that’s implemented in both the car and bike classes. When defining a method that accepts IVehicle as a parameter
Tag: interface
Attributes / member variables in interfaces?
I wish to know is there any way in which I can make it compulsory for the implementer class to declare the objects handles/primitives as they do with methods. for e.g.: In the above method how can we compel Tile class to declare height and width attributes using the interface? For some reason I wish to do it with interface
The purpose of interfaces continued
OK so I gather that Interfaces are a way to enforce that an object implements a certain amount of functionality, without having to use inheritance. Kind of like a contract. And I semi see the point of them. But if all you have in the interface is: and it has no implementation as such, then whoever uses your interface has