Abstract type: Difference between revisions
Content added Content deleted
m (→Abstract type: Typo fixed) |
|||
Line 38: | Line 38: | ||
=={{header|Java}}== |
=={{header|Java}}== |
||
Methods that don't have an implementation are called abstract methods in Java. A class that contains an abstract method or inherits one but did not override it must be an abstract class; but an abstract class does not need to contain any abstract methods. An abstract class cannot be instantiated. If a method is abstract, it must be public or protected |
|||
<java>public abstract class Abs { |
<java>public abstract class Abs { |
||
abstract public int method1(double value); |
abstract public int method1(double value); |
||
Line 46: | Line 46: | ||
} |
} |
||
}</java> |
}</java> |
||
Interfaces in Java may not |
Interfaces in Java may not implement any methods and all methods are implicitly public and abstract. |
||
<java>public interface Inter { |
<java>public interface Inter { |
||
int method1(double value); |
|||
int method2(String name); |
|||
int add(int a, int b); |
|||
}</java> |
}</java> |
||