The problem of Object inheritance in scala

:
class Test{}
object Driver extends  Test{

}


:

abstract Fruit{

val name :String 
val color :String 
}

object Fruit{
 object Apple extends Fruit("apple","red")
  val menu=List(Apple)
}

question:
(1) Why object in scala can also inherit from class or trait using extends. How to understand

(2) Why does extens Fruit ("A", "B") take two parameters here in the second paragraph of code?

Thank you for answering questions!

add:

clipboard.png

Feb.28,2021

    The
  1. scala design is like this: a object can extend a class or trait, and the result is an object that extends the specified class or trait and has all the features given in the object definition. The difference between object and class is that you can understand that object is a singleton pattern, which can only have one, while class can create more than one.
  2. What is abstract Fruit ? And the code blocks are enclosed in large brackets, and the two values in Fruit are both val . You must use the main constructor method instead of parentheses. The following can be compiled:
  
    The object in
  1. scala is not a simple concept of an object, it can also be seen as a class. Similar to the tool class in java. You can inherit other classes.
  2. inherits the Fruit class, setting name and color. whenever you instantiate an object with Apple Then initializing during inheritance avoids the problem of initializing properties each time when Apple is instantiated multiple times.
  • An algorithm problem

    question: there are two actions for a user to invest and refund (for example, if An invests 100000 yuan, then he will get a rebate of 10 yuan after maturity). When the user does not make any investment within 6 months, the next investment will be regard...

    Jul.11,2022
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e475ca-44c28.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e475ca-44c28.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?