What is 'TRAITS' in Scala

0 votes
Can anyone explain the term with an example how Trait works in Scala?
Jul 31, 2019 in Apache Spark by pavitra
58 views

1 answer to this question.

0 votes

Hi,

Traits are basically Scala's workaround for the JVM not supporting multiple class inheritance.

 Here is an example of traits in Scala:

trait Car {
  val brand: String
}

trait Costly{
  val cost: Int 
}

trait Milege{
  val milege: Int
}

class Audi extends Car with Shiny with Miles{
  val brand = "Audi"
  val cost = 140000
  val milege = 20
}

I hope it helps.

answered Jul 31, 2019 by Gitika
• 25,440 points

Related Questions In Apache Spark

0 votes
1 answer

What is ofDim in Scala?

Hey, ofDim() is a method in Scala that ...READ MORE

answered Jul 24, 2019 in Apache Spark by Gitika
• 25,440 points
144 views
0 votes
1 answer

What is exception propagation in Scala?

Hi, When a function experiences an exception, it ...READ MORE

answered Jul 25, 2019 in Apache Spark by Gitika
• 25,440 points
38 views
0 votes
1 answer

What is BitSet in Scala?

Hey, A BitSet is a set of non-negative ...READ MORE

answered Jul 25, 2019 in Apache Spark by Gitika
• 25,440 points
47 views
0 votes
1 answer

What is Streams in Scala?

Hi, A stream is a lazy list as ...READ MORE

answered Jul 25, 2019 in Apache Spark by Gitika
• 25,440 points
52 views
+1 vote
1 answer
+1 vote
1 answer

Hadoop Mapreduce word count Program

Firstly you need to understand the concept ...READ MORE

answered Mar 16, 2018 in Data Analytics by nitinrawat895
• 10,840 points
3,859 views
0 votes
1 answer

hadoop.mapred vs hadoop.mapreduce?

org.apache.hadoop.mapred is the Old API  org.apache.hadoop.mapreduce is the ...READ MORE

answered Mar 16, 2018 in Data Analytics by nitinrawat895
• 10,840 points
527 views
+1 vote
11 answers

hadoop fs -put command?

put syntax: put <localSrc> <dest> copy syntax: copyFr ...READ MORE

answered Dec 7, 2018 in Big Data Hadoop by Aditya
20,400 views
0 votes
1 answer

What is “Unit” and “()” in Scala?

Hey, Unit is a subtype of scala.anyval and ...READ MORE

answered Jul 24, 2019 in Apache Spark by Gitika
• 25,440 points
55 views
0 votes
1 answer

What is the advantage of having immutability in design for Scala programming language?

Hi, Scala uses immutability by default in most ...READ MORE

answered Jul 24, 2019 in Apache Spark by Gitika
• 25,440 points
50 views