What’s the difference between an interface and an abstract class in Java?
This is an awesome analogy created by Jay. Couldn't help but share =). Thanks Jay !
How about an analogy:
When I was in the Air Force, I went to pilot training and became a USAF pilot. At that point I wasn't qualified to fly anything, and had to attend aircraft type training. Once I qualified, I was a pilot (Abstract class) and a C-141 pilot (concrete class). At one of my assignments, I was given an additional duty: Safety Officer. Now I was still a pilot and a C-141 pilot, but I also performed Safety Officer duties (I implemented ISafetyOfficer, so to speak). A pilot wasn't required to be a safety officer, other people could have done it as well.
All USAF pilots have to follow certain Air Force-wide regulations, and all C-141 (or F-16, or T-38) pilots 'are' USAF pilots. Anyone can be a safety officer. So, to summarize:
added note: this was meant to be an analogy to help explain the concept, not a coding recommendation. See the various comments below, the discussion is interesting.
Reference: stackoverflow
Original Author: JAY, http://stackoverflow.com/users/118962/jay
|