[Scala Object-Oriented] 31. Inheritance

Insert image description here

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 {
   
    
    
  // 父类的字段和方法

Guess you like

Origin blog.csdn.net/m0_47256162/article/details/132160236