Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


Explain traits in scala.



Explain traits in scala...

Answer / Divya Chaudhary

In Scala, a trait is a type that can contain both abstract members (methods and variables) as well as concrete implementations. Traits are similar to interfaces in Java but have some additional features, such as the ability to provide default implementations for methods. A class or another trait can mix in multiple traits to inherit their behavior. When a class mixes in a trait, it must provide an implementation for any abstract members that the trait does not provide a default implementation for. For example:nn```scalantrait Printable {n def print(): Unitn}nclass Person(val name: String) extends Printable {n def print() = println(s"Person: $name")n}nval person = new Person("John Doe")nperson.print() // Output: Person: John Doe

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Scala Interview Questions

Why do we need app in scala?

1 Answers  


What do you understand by tail recursion in scala ?

1 Answers  


What is the difference between val and var in Scala?

1 Answers  


What is an Higher-Order Function (HOF)?

1 Answers  


What does map in scala collection?

1 Answers  


What is the default Unit and Functional Testing Framework for Play? What is the default Build Tool for Play? What is the Default Template Engine for Play? What is the built-in Web Server available in Play Framework?

1 Answers  


Explain the difference between a trait and an abstract class?

1 Answers  


When can you use traits?

1 Answers  


Explain the functionality of yield?

1 Answers  


What is the syntax for function declaration in scala?

1 Answers  


What is implicit class in scala?

1 Answers  


What is the use of 'object' keyword in Scala? How to create Singleton objects in Scala?

1 Answers  


Categories