Forums Register Login

Difference Between Abstract Class and Interface

+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 

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);
}
}
+Pie Number of slices to send: Send
ABSTRACT CLASSES :-
Can't have MULTIPLE INHERITANCE.
INTERFACES :-
Supports MULTIPLE INHERITANCE.
+Pie Number of slices to send: Send
BTW, both abstract classes and interfaces cannot be instantiated.
+Pie Number of slices to send: Send
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.
Why does your bag say "bombs"? The reason I ask is that my bag says "tiny ads" and it has stuff like this:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 856 times.
Similar Threads
abstract class & interface
diff between abstract class and inheritance
Interface
abstract and interfaces
Difference between abstract and interface,not Syntactical diff
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 03:46:46.