How do we make a call to a private primary constructor in scala?



How do we make a call to a private primary constructor in scala?..

Answer / Kumar Gaurav

In Scala, you cannot directly call a private primary constructor. You should create an object companion that defines the application's entry point and use it instead.nExample:n```scalanclass MyClass private(val data: Int)nobject MyClass{n def apply(data: Int): MyClass = new MyClass(data)n}nMyClass(10)n```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Scala Interview Questions

What is the equivalent construct of Scala’s Option in Java SE 8? What is the use of Option in Scala?

1 Answers  


What is anonymous (lambda) function in scala?

1 Answers  


What is implicit class in scala?

1 Answers  


What does f method in scala string interpolation?

1 Answers  


Popular clients who are using Play and Scala to develop their applications?

1 Answers  


What is bitset in scala?

1 Answers  


What is the use of auxiliary constructors in scala? explain the rules to follow in defining auxiliary constructors in scala?

1 Answers  


What are the data types in scala?

1 Answers  


What is a custom exception in scala?

1 Answers  


What are the available Build Tools to develop Play and Scala based Applications?

1 Answers  


Explain the main drawback of scala language?

1 Answers  


What are the advantages of Play/Scala stack to develop web applications?

1 Answers  


Categories