Abstract type: Difference between revisions

Content added Content deleted
m (→‎Abstract type: Typo fixed)
Line 38: Line 38:


=={{header|Java}}==
=={{header|Java}}==
Abstract classes in Java can define methods and aren't required to have abstract methods. If a method is abstract, it must be public or protected
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 define any methods and all methods must be public and can be abstract.
Interfaces in Java may not implement any methods and all methods are implicitly public and abstract.
<java>public interface Inter {
<java>public interface Inter {
public int method1(double value);
int method1(double value);
public int method2(String name);
int method2(String name);
abstract public int add(int a, int b);
int add(int a, int b);
}</java>
}</java>