Article directory
In Scala, inheritance is a fundamental feature of object-oriented programming that is used to create a class (subclass) that inherits properties and methods from another class (parent class). Scala uses the keyword extends
to implement class inheritance.
1. Inheritance syntax
In Scala, use the extends
keyword to implement class inheritance. Subclasses inherit the properties and methods of the parent class, and can override the methods of the parent class in the subclass. The basic syntax of inheritance is as follows:
class Parent {
// 父类的字段和方法