The basic difference would be interface cannot have any method definition or variables declared while an abstract method can have them. Now what is the difference between an abstract class and an interface when they contain only the method signatures in them. In what situations will you use either of them. Can they be used interchangeably.

Recommended Answers

All 7 Replies

You can implement multiple interafaces but you can extend only one class. So be careful with abstract classes in the first place and the only reason to use an abstract class in the case listed above is when there is some common, non-trivial, implementation to be considered as well.

You CAN declare variables in an interface (Language spec chapter 9.3).

You can implement multiple interafaces but you can extend only one class. So be careful with abstract classes in the first place and the only reason to use an abstract class in the case listed above is when there is some common, non-trivial, implementation to be considered as well.

yes.. any other differences? cause when i'm finished explaining all these stuff to my interviewer he was not satisfied. i don't know what else have i missed. i have been over and over this topic all over the internet and i guess i have pretty much summarized every thing to the interviewer.

Well, I have no idea what you actually said, nor what the interviewer actually asked (not just your recollection of your interpretation of the question), nor how, exactly, the interviewer expressed his "dissatisfaction" with the answer, nor what, exactly the interviewer was aiming at with the question, so I can't say.

If you want to know the complete answer see the JLS and Google.

when you implement an interface, you'll have to implement all methods in your class.
like if interface A has methods A1 and A2, your class should implement both methods even if you don't use any of them.

Abstract classes, you may override the methods that you want to customize for your class

when you implement an interface, you'll have to implement all methods in your class.
like if interface A has methods A1 and A2, your class should implement both methods even if you don't use any of them.

Abstract classes, you may override the methods that you want to customize for your class

when you implement an interface, you'll have to implement all methods in your class.
like if interface A has methods A1 and A2, your class should implement both methods even if you don't use any of them.

Abstract classes, you may override the methods that you want to customize for your class

Not when those abstract class methods are also abstract (which the OP explicitly stated they were).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.