![]() |
|
Abstract Classes and Methods, Free online Core Java Programming Tutorial, Learn Java Programming Language online for free... |
| Lessons | Abstract Classes and Methods |
|
|
Abstract Methods An abstract method is a method that is declared in a (super)class, but not defined. In order to be instantiated, a subclass must provide the definition. Abstract Classes An abstract class is any class that includes an abstract method. It is similar to Pure virtual in C++. If a class includes an abstract method, the class must be declared abstract, too. Code Example: abstract class AbstractClass {
abstract public void Print();
// no body, just the function header
}
class MyConcreteClass extends AbstractClass {
public void Print() {
// actual code goes here
}
}
Important points to be remembered:
Next >>> Lesson No. 12: Java Interfaces
|