Jump to content

Abstract type: Difference between revisions

m
(Groovy solution added)
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).
<lang groovy>public interface Interface {
int method1(double value);
int method2(String name);
int add(int a, int b);
}</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".
<lang groovy>public abstract class Abstract1 {
abstract public int methodA(Date value);
abstract protected int methodB(String name);
int add(int a, int b) { a + b }
}</lang>
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.