inheritance in Scala: Construction of Super class, Field rewrite, method rewriting
About the construction of Super class: Superclass can be restricted in subclass without location, can call method of parent class in subclass
Field overrides in class: You can reassign a value by adding an override in front of the re-write field
Method overrides in class: Similar to field overrides, parameters, method names are the same
class Person1 (Val name:string, var age:int) { println ("The primary constructor of person") = "BJU" = "8 hours" = "I am a person1!" }classextends Person1 (name, age) { println ("This is the subclass of Person, Primary constructor of Worker ") =" Spark " Super. Sleep}
Abstract classes, abstract fields, abstract methods
Abstract class implementation: in front of an abstract keyword, the field inside can not be assigned value, the method can not be implemented, if the field is not abstract class can be used instead of placeholders
Abstract field implementation: You can add override to assign a value before a field
Abstract method Implementation: Add an override keyword before the method
class abstractclassops{ = _}abstractclass Superteacher (val name:string) { var id:int var age:int def teach}classextends superteacher (name) { = name.hashcode () = override def teach{ println ("Teaching!!!" ) }}
trait of interfaces in Scala and trait implementations in objects
Scala interface trait implementation: Scala interface with trait to decorate, and Java with interface to decorate, method can be abstract method and no implementation of empty method, interface implementation with extends to operate, the method can be implemented also can not implement
The trait implementation in the object: the interface can be implemented by multiple classes, if a class is not implemented, the instance object is a method that can be implemented with other objects with Otherclass, you can call the inside method, so flexibility is big
Trait logger{//def log (msg:string)def log (msg:string) {}}classConcreteloggerextendsLogger with cloneable{//override def log (msg:string) = println ("LOG:" + msg)def concretelog{log ("It ' s Me!!!")}}trait Traitloggerextendslogger{override def log (msg:string) {println ("Traitlogger Log content is:" +msg)}} Trait traitloggered{def loged (msg:string) {println ("Traitloggered Log content is:" +msg)}} Trait Consoleloggerextendstraitlogger{override def log (msg:string) {println ("Log from Console:" +msg)}}
In fact, learning Scala related knowledge is to be able to develop in the future to big data, now although the work is background development, but also what to understand a little. Also believe that the surrounding benefits, so the development of multi-dimensional. Make progress every day, stick to it!
Video sharing Address: Http://pan.baidu.com/s/1c0hjFpA
Big Data series Cultivation-scala Course 04