File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Core Java Releated Quesstion 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 "Core Java Releated Quesstion" Watch "Core Java Releated Quesstion" New topic
Author

Core Java Releated Quesstion

pinakin raval
Greenhorn

Joined: Jun 28, 2005
Posts: 5
What is the difference between the abstract class and the interface
Shalini Chandel
Ranch Hand

Joined: May 05, 2005
Posts: 115
An Abstract class declares have at least one instance method that is declared abstract which will be implemented by the subclasses. An abstract class can have instance methods that implement a default behavior.

An Interface can only declare constants and instance methods, but cannot implement default behavior.

Hope this help...

Regards,
Shalini


SCJP 1.4
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1535
further you can assume, an interface is a COMPLETE abstract class. :-)


Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
no. In interface in Java has a somewhat similar role to a pure virtual class in C++ (though there are important (mainly philosophical) differences as well).

There's no such beast as a "complete virtual" class and interfaces aren't classes (even if they compile to .class files, probably because the JVM designers didn't want to introduce yet another file type).


42
Mikalai Zaikin
Ranch Hand

Joined: Jun 04, 2002
Posts: 3231
    
    6
Originally posted by Shalini Chandel:
An Abstract class declares have at least one instance method that is declared abstract which will be implemented by the subclasses. An abstract class can have instance methods that implement a default behavior.


Wrong.

Abstract class :

1. May have no methods at all:



2. May have no abstract methods (all methods are concrete):



regards,
MZ


Free SCDJWS 5.0 Study Guide - SCDJWS 5.0 Quiz (How to get SCDJWS 5.0 Quiz)
Java Platform, Enterprise Edition 6 Web Services Developer Certified Expert Exam Study Guide and Quiz
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1535
Originally posted by Jeroen Wenting:
no. In interface in Java has a somewhat similar role to a pure virtual class in C++ (though there are important (mainly philosophical) differences as well).

There's no such beast as a "complete virtual" class and interfaces aren't classes (even if they compile to .class files, probably because the JVM designers didn't want to introduce yet another file type).


interfaces aren't classes? Agreed Wenting. But I said you can assume them to be COMPLETE abstract classes. I dont want to talk of C++ or terms like "virtual" in an SCJP forum, the following link would speak what I meant...

http://www.google.co.in/search?biw=800&hl=en&q=%22interfaces+are+abstract+classes%22+java&btnG=Google+Search&meta=
[ June 28, 2005: Message edited by: Akhil Trivedi ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Core Java Releated Quesstion