Q:

scala trait inheritance exercise with answers

// Scala program to illustrate how to  
// create traits 
  
// Trait  
trait MyTrait 
{ 
    def pet  
    def pet_color 
} 
  
// MyClass inherits trait 
class MyClass extends MyTrait 
{ 
      
    // Implementation of methods of MyTrait 
    def pet() 
    { 
        println("Pet: Dog") 
    } 
      
    def pet_color() 
    { 
        println("Pet_color: White") 
    } 
      
    // Class method 
    def pet_name() 
    { 
        println("Pet_name: Dollar") 
    } 
}  
  
object Main  
{ 
      
    // Main method 
    def main(args: Array[String])  
    { 
        val obj = new MyClass(); 
        obj.pet(); 
        obj.pet_color(); 
        obj.pet_name(); 
    } 
} 
0

New to Communities?

Join the community