Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Core Java Releated Quesstion

 
pinakin raval
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the difference between the abstract class and the interface
 
Shalini Chandel
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Akhilesh Trivedi
Ranch Hand
Posts: 1599
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
further you can assume, an interface is a COMPLETE abstract class. :-)
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Mikalai Zaikin
Ranch Hand
Posts: 3330
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Akhilesh Trivedi
Ranch Hand
Posts: 1599
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic