Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #33420
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: How to write constructor for an abstarct class? |
| Date | 2015-12-28 17:43 -0500 |
| Organization | A noiseless patient Spider |
| Message-ID | <n5sdqd$u7s$1@dont-email.me> (permalink) |
| References | (4 earlier) <n5rv13$4vh$1@news.albasani.net> <96fe5a20-3ea4-4578-89c7-4f7e324fcfd0@googlegroups.com> <n5s9e0$ol3$1@news.albasani.net> <n5sam1$r7v$1@news.albasani.net> <f00d53a6-ee30-47db-aee7-80bffade466c@googlegroups.com> |
On 12/28/2015 4:58 PM, Eric Douglas wrote:
>
> Previously an abstract class was intended for partial coding, if we have a class which has multiple subclasses which have at least one abstract method which will need different implementations in the subclasses and at least one concrete method which can have common code for all subclasses. If everything was abstract it probably made more sense to begin with to make it an interface, which is what java.awt did with Shape. Now that interfaces can contain the methods with the common code, what advantage do you get for making the abstract class, when as you say there is the disadvantage that you can never add another abstract method to it without modifying all subclasses? The same would be true for the interface but you could always add a second interface to implement, while the subclasses can only extend one class.
Interfaces with default method implementations cannot completely
replace abstract classes, as the latter can do a few things that the
former cannot:
- An abstract class can declare a final method, but an interface
cannot declare a final method, default or otherwise.
- An abstract class can declare a non-final data element, but all
data elements of an interface are final.
- An abstract class can declare non-static data elements, but all
data elements of an interface are static.
- An abstract class can override a method of Object and provide
an implementation, but an interface's override must be abstract
(e.g., `public String toString() {...}' works in an abstract
class, but `default public String toString() {...}' is impossible
in an interface).
- An abstract class can declare private, package-private, and
protected methods and data elements, but everything in an
interface must be public.
... and there are probably additional differences I've overlooked.
Some of the differences might be regarded as advantages of interfaces
over classes (e.g., non-final non-private fields are dubious at best),
but for some it seems to me that classes offer more flexibility and
perhaps more power.
--
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How to write constructor for an abstarct class? Xue Feng <xf.lotus@yahoo.com> - 2015-12-28 20:44 +0800
Re: How to write constructor for an abstarct class? Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-12-28 08:21 -0500
Re: How to write constructor for an abstarct class? Jan Burse <janburse@fastmail.fm> - 2015-12-28 19:20 +0100
Re: How to write constructor for an abstarct class? Jan Burse <janburse@fastmail.fm> - 2015-12-28 19:25 +0100
Re: How to write constructor for an abstarct class? Jan Burse <janburse@fastmail.fm> - 2015-12-28 19:28 +0100
Re: How to write constructor for an abstarct class? Lew <lewbloch@gmail.com> - 2015-12-28 10:40 -0800
Re: How to write constructor for an abstarct class? Eric Douglas <e.d.programmer@gmail.com> - 2015-12-28 10:42 -0800
Re: How to write constructor for an abstarct class? Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-12-28 14:29 -0500
Re: How to write constructor for an abstarct class? j4n bur53 <janburse@fastmail.fm> - 2015-12-28 22:26 +0100
Re: How to write constructor for an abstarct class? Eric Douglas <e.d.programmer@gmail.com> - 2015-12-28 13:37 -0800
Re: How to write constructor for an abstarct class? j4n bur53 <janburse@fastmail.fm> - 2015-12-28 22:47 +0100
Re: How to write constructor for an abstarct class? Eric Douglas <e.d.programmer@gmail.com> - 2015-12-28 13:58 -0800
Re: How to write constructor for an abstarct class? j4n bur53 <janburse@fastmail.fm> - 2015-12-28 23:06 +0100
Re: How to write constructor for an abstarct class? Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-12-28 17:43 -0500
Re: How to write constructor for an abstarct class? Lew <lewbloch@gmail.com> - 2015-12-28 15:14 -0800
Re: How to write constructor for an abstarct class? j4n bur53 <janburse@fastmail.fm> - 2015-12-29 15:02 +0100
Re: How to write constructor for an abstarct class? Arne Vajhøj <arne@vajhoej.dk> - 2015-12-29 15:37 -0500
Re: How to write constructor for an abstarct class? Arne Vajhøj <arne@vajhoej.dk> - 2015-12-29 15:28 -0500
Re: How to write constructor for an abstarct class? Arne Vajhøj <arne@vajhoej.dk> - 2015-12-29 15:21 -0500
Re: How to write constructor for an abstarct class? Arne Vajhøj <arne@vajhoej.dk> - 2015-12-29 15:22 -0500
Re: How to write constructor for an abstarct class? j4n bur53 <janburse@fastmail.fm> - 2015-12-29 16:24 +0100
csiph-web