scala basic question - Object Oriented 1

Exercise 1

  Prepared based computer, comprising CPU, memory, hard drives and other properties, getDetails method for returning details computer.

  PC write subclass inherits computer class, add unique attributes of the brand [brand]

  Notepad writing classes, inheritance computer class, add a unique attribute [color color]

  Written test object, pc and notepad to create an object in the main method, the object-specific properties are assigned, and red computer classes inherit property assignment, and using the print output.

object work03 {
  def main(args: Array[String]): Unit = {
    var pc=new PC
    pc.CPU="12核"
    pc.neicun="32G"
    pc.yingpan="2T"

    var notepad=new NotePad
    notepad.brand = "Dell"
    
    notepad.getDetails()
  }
}
class PC{
  var CPU:String=_
  was neicun: String = _
  var yingpan:String=_
  def getDetails():Unit={
    println ( "CPU =" + CPU + ", memory =" + neicun + ", hard" + yingpan)
  }
}
class NotePad extends PC {
  was fire: String = _
}

  

Guess you like

Origin www.cnblogs.com/liangyan131/p/12000282.html