Yahoo Interview Question
Software Engineer / DevelopersCountry: India
Interview Type: Phone Interview
1)Wht is abstraction?
Abstraction in Java allows the user to hide non-essential details relevant to user.
2)Diff between abstract class nd interface nd when u use one?
Abstract class can have concrete methods.We can extend only one abstract class in our class.
Interface can't have concrete methods. We can implement n number of interface in our class.
If we need same change everywhere, we should take abstract class.If all implemented class need different changes we should go for interface.
When you have a consistently changing design of your base class ,you should go for an abstract class as the classes which extend these base classes will automatically inherit functionality from the base classes.But instead if you use a interface,not only the interfaces would have to be changed but also the classes implementing the interface would have to be changed.So inshort when you have a consistently changing design you should opt for a Abstract class and vice versa.
- gandheshantanus March 16, 2012