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
posted
0
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.
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); } }
BTW, both abstract classes and interfaces cannot be instantiated.
Thomas Paul
mister krabs
Ranch Hand
Joined: May 05, 2000
Posts: 13974
posted
0
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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: Difference Between Abstract Class and Interface