aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes what's difference between an interface and abstract class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "what Watch "what New topic
Author

what's difference between an interface and abstract class

vasanthi
Greenhorn

Joined: Oct 22, 2000
Posts: 8
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
bill bozeman
Ranch Hand

Joined: Jun 30, 2000
Posts: 1070
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
Velmurugan Periasamy
Ranch Hand

Joined: Nov 09, 2000
Posts: 95
Check out this link
http://java.sun.com/docs/books/tutorial/java/interpack/interfaceDef.html
HTH
------------------
Velmurugan Periasamy http://www.geocities.com/velmurugan_p/


------------------------------------------------------------------------------------<BR>Velmurugan Periasamy<BR>Sun Certified Java Programmer for Java 2 Platform<BR>Sun Certified Web Component Developer for J2EE platform<BR>Sybase Certified EAServer Developer (similar to jCert level 3)<BR>------------------------------------------------------------------------------------<BR>Study notes for Sun Java Certification<BR><A HREF="http://www.geocities.com/velmurugan_p/" TARGET=_blank rel="nofollow">http://www.geocities.com/velmurugan_p/</A><BR>------------------------------------------------------------------------------------
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
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).
chak ms
Greenhorn

Joined: Dec 11, 2000
Posts: 12
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

Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what's difference between an interface and abstract class