java - Difference between Interface And Abstract Class -
this question has answer here:
- interface vs abstract class (general oo) 32 answers
- what difference between interface , abstract class? 32 answers
why use interface while have given abstract class ?
interface { void show(); } class testa implements { public void show(){} } abstract class b { abstract void show(); } class testb extends b { public void show(){} }
interfaces , abstract classes different in interfaces describe behavior, while abstract classes define partial implementations. interfaces have advantage can implemented object provides necessary method, regardless of classes object inherits from.
abstract methods typically used provide partial implementation. example list interface defines behavior of list collections, compared abstractlist provides of methods needed list implementations, make easier implement list. lists aren't required inherit abstractlist, many implementations do, code uses list never has care whether implementation use extends abstractlist or not.
some people use abstract classes substitute interfaces, considered anti-pattern.
Comments
Post a Comment