aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Difference Between Abstract Class and Interface 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 "Difference Between Abstract Class and Interface" Watch "Difference Between Abstract Class and Interface" New topic
Author

Difference Between Abstract Class and Interface

JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
I think the differences between Abstract Class and Interface are:
Abstract Classes:
1. can have constructors
2. cannot be instantiated
3. classes use 'extends' to extend abstract classes
Interfaces:
1. only have public final static data and public abstract
methods
2. all methods have void return type
3. interface methods cannot be final, static, synchronized,
or native
4. cannot have constructor
5. classes use 'implements' to implement interfaces
6. interfaces use 'extends' to extend other interfaces
Are there any other attributes can be added?
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Abstract Classes
----------------
1. Abstract classes can not have constructors as they can never be constructed.
Interfaces
----------
2. This is incorrect. methods can have any return type.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Bin Wang
Ranch Hand

Joined: May 01, 2001
Posts: 82
Originally posted by Thomas Paul:
Abstract Classes
----------------
1. Abstract classes can not have constructors as they can never be constructed.

Thomas,
I think abstract class can have constructor(s), although it doesn't make sense. See the following code, it compiles and runs well and outputs 1.
abstract class Test {
static int i=1;
Test() {i=5;}
public static void main (String[] args) {
System.out.println(Test.i);
}
}
krutika burse
Greenhorn

Joined: May 05, 2001
Posts: 9
ABSTRACT CLASSES :-
Can't have MULTIPLE INHERITANCE.
INTERFACES :-
Supports MULTIPLE INHERITANCE.
js yang
Ranch Hand

Joined: May 09, 2001
Posts: 40
BTW, both abstract classes and interfaces cannot be instantiated.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Shows what happens when you respond before your first cup of coffee.
Abstract classes can have constructors which will be invoked when a concrete implementation of that abstract class is instantiated. Constructors themseves can not be abstract.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Difference Between Abstract Class and Interface
 
Similar Threads
Interface
abstract and interfaces
Difference between abstract and interface,not Syntactical diff
diff between abstract class and inheritance
abstract class & interface