Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialmohamadreza azadi
5,167 Pointswhat's Different between abstract and interface?
I'm so confused about this subject what's different between abstract and interface please help me
2 Answers
Ashton Chingovo
8,055 PointsAn abstract class cannot be instantiated i.e. you cannot create an object of that class. You only extend it and override its methods if you want. http://www.geeksforgeeks.org/abstract-classes-in-java/
An Interface however is a blueprint of a class that behaves as a contract, when implemented it dictates that you have to override all its methods additionally you can instantiate an interface unlike an abstract class. http://www.geeksforgeeks.org/interfaces-in-java/
Ryan Worcester
2,445 Points- You can't instantiate either of them.
- Conceptually an interface is a contract while an abstract class is a partially complete class.
- Normally an interface can't have any method implementations but more recent Java has changed that.
- Any class (abstract or normal) can only extend 1 class but can implement any number of interfaces. An interface can't implement but can extend any number of interfaces.
- Interface fields can only be public static final (which is implicit) but abstract can have any kind of field.
- Interface methods can only be public (which is implicit), static is optional. Abstract can have any kind of method.