"Spark Asia-Pacific Research series" Spark Combat Master Road-2nd Chapter hands-on Scala 2nd bar: Hands-on Scala object-oriented programming (2)

Source: Internet
Author: User

3, hands on the abstract class in Scala

The definition of an abstract class requires the use of the abstract keyword:

The above code defines and implements the abstract method, it is important to note that we put the direct running code in the trait subclass of the app, about the inside of the app helps us implement the Main method and manages the code written by the engineer;

Here's a look at the use of uninitialized variables in an abstract class:

4, hands-on trait in Scala

Trait is similar to the interface in Java 8 that can have the default method.

trait can be implemented in a method, or with an abstract method, using trait is mixed with the class.

let's look at an example of trait:

Note that we use the use of trait here is extends, because Concretelogger does not inherit other classes or trait's sake;

the child trait can override the method that implements the parent trait:

If the trait is used, the override keyword is required if the method already implemented in the parent trait is overwrite:

Here's a look at mixing trait in the object:

Spark Asia-Pacific Research series, spark Combat Master Road-2nd Chapter hands-on Scala 2nd bar: Hands on Scala object-oriented programming (2)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.