Abstract type: Difference between revisions

Line 1,422:
 
=={{header|Java}}==
Java has an ''<code>interface''</code> and an ''<code>abstract class''</code>. Neither of which can be instantiated, and require some sort of implementation or abstraction.<br />
For an ''<code>interface''</code>, only the ''<code>private''</code> and ''<code>default''</code> access modifiers are allowed, which also implies they require code.<br />
A ''<code>private''</code> method cannot be overridden by a sub-class, and a ''<code>default''</code> method, optionally, can.<br />
A method with no access modifier is inherently ''<code>public''</code>, must not contain code, and requires implementation by its sub-class.<br />
Member fields are allowed, although are effectively ''<code>public</code>, <code>final''</code>, and ''<code>static''</code>, thus requiring a value.<br />
Here is an example of an ''<code>interface''</code>.
<syntaxhighlight lang="java">
interface Example {
Line 1,456:
}
</syntaxhighlight>
The ''<code>abstract class''</code> is very generalized, and for the most part is just a ''<code>class''</code> that allows for un-implemented methods.<br />
The ''<code>default''</code> access modifier is not used here, as it applies only to an ''<code>interface''</code>.<br />
Additionally, if a method is marked ''<code>abstract''</code>, then the ''<code>private''</code> access modifier is not allowed, as the concept does not apply.<br />
Here is an example of an ''<code>abstract class''</code>.<br If the class contains ''abstract'' methods then the class definition must also have the ''abstract'' keyword./>
If the class contains <code>abstract</code> methods then the class definition must also have the <code>abstract</code> keyword.
<syntaxhighlight lang="java">
abstract class Example {
Line 1,476 ⟶ 1,477:
}
</syntaxhighlight>
Here is an example of a class which ''<code>extends''</code> an ''<code>abstract class''</code>.
<syntaxhighlight lang="java">
class ExampleImpl extends Example {
118

edits