Abstract type: Difference between revisions
Content added Content deleted
(Groovy solution added) |
|||
Line 514: | Line 514: | ||
As in [[Java]], methods that are declared but not implemented are called "abstract" methods. An interface is a class-level typing construct that can only contain abstract method declarations (well, and constants, but pay no attention to those). |
As in [[Java]], methods that are declared but not implemented are called "abstract" methods. An interface is a class-level typing construct that can only contain abstract method declarations (well, and constants, but pay no attention to those). |
||
<lang groovy>public interface Interface { |
<lang groovy>public interface Interface { |
||
int method1(double value) |
int method1(double value) |
||
int method2(String name) |
int method2(String name) |
||
int add(int a, int b) |
int add(int a, int b) |
||
}</lang> |
}</lang> |
||
An abstract class may implement some of its methods and leave others unimplemented. The unimplemented methods and the class itself must be declared "abstract". |
An abstract class may implement some of its methods and leave others unimplemented. The unimplemented methods and the class itself must be declared "abstract". |
||
<lang groovy>public abstract class Abstract1 { |
<lang groovy>public abstract class Abstract1 { |
||
abstract public int methodA(Date value) |
abstract public int methodA(Date value) |
||
abstract protected int methodB(String name) |
abstract protected int methodB(String name) |
||
int add(int a, int b) { a + b } |
int add(int a, int b) { a + b } |
||
}</lang> |
}</lang> |