Abstract class in x++
-> Abstract classes are identified by the keyword abstract.
-> They cannot be instantiated but require a subclass that is inherited from the abstract class.
-> Abstract classes are used to implement a concept that the subclass will then complete.
-> Abstract methods can also be declared in abstract classes.
-> Abstract methods do not allow code or declarations in the method.
-> A subclass must extend the abstract class to use the abstract method.
Example:
abstract class Vehicle
{
str owner;
int age;
void printInfo()
{
Info(strfmt("%1, %2",owner, age));
}
abstract void operate() // abstract method
{
//Abstract methods do not allow code or declarations in the method.
}
}
Example:
class Car extends Vehicle // Car is a subclass that extends Vehice (abstract class) to use abstract method called Operate (abstract method name)
{
str model;
void printInfo()
{
// overriding default functionality
Info(strfmt("%1, %2, %3",owner, age, model));
}
void operate()
{
Info('running');
}
}
Comments
Post a Comment