vasanthi, We have a naming policy here at the Ranch, and you name doesn't follow the rules. Could you please re-register with a more apprpriate name. Check out this link for more details: www.javaranch.com/name.jsp Thanks, Bill Also, I am going to move this to the Certification Forum since it doesn't relate directly to Mock Exam errors. Bill
That's an easy one! An abstract has a mixture of complete methods, and declarative methods. The methods that do not have anycode are declared abstract indicating the developer(s) that the implementation of the class is not complete. One has to extend an abstract class and provide the implementation of the abstract methods.
In an interface, all the methods are just declarative. ie., they are just declared with no body. So, theoretically an interface is a "pure abstract class".
One has to impelement an interface and write code for the methods declared therein. If you browse the Java API documentation, you will find a lot of excellent examples for interfaces and abstract classes. Hope that helps! Ajith
Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Interfaces and abstract classes are related in the means of implementing methods own by interface or abstract class. U can't instantiate either Interface or abstract class. Interface is just collection of method names without body. It means, if a class implements any interface, it has to implement all the methods in that interface. It means, u have to define those methods which are declard in the interface of the class. No method has definition in the interfaces. U have to provide ur own definition whenever u want. Where as in abstract classes, these may contain data members and collection of methods too. This may contain non abstract methods too. Non abstract methods means the methods which have definition and abstract means, which don't have method definition in the class definition itself. Whenever u extend a class with an abstract class, u have to provide the definitions to all the nonabstract methods of the abstract class. To make it more clear for u, If an abstract class contains only abstract methods and no non abstract methods and no data members becomes an interface. I hope this could help u to understand about interfaces and abstract classes. If u have still more doubts, u can post a reply to this. with regards chak
Originally posted by vasanthi: hi all, I am preparing for the scjp exam,can anybody tell me the difference between an interface and an abstract class.i am just getting confused,please explain me in detail. regards vasanthi
Joined: Mar 17, 2000
Chak, One small correction to what you said - Interfaces can contain data members. They are implicitly public and final, cannot be declared private and they have to be initialized. Ajith
subject: what's difference between an interface and abstract class