Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
object HelloWorld {
/* This is my first java program.
* This will print 'Hello World' as the output
*/
def main(args: Array[String]) {
println("Hello, world!") // prints Hello World
}
}
class MyClass ( val name : String, val rollno : Int) /* Primary Constructor */
{ //When a class is instantiated everything inside the class get executed except the methods. Its unique features of scala unlike java and c++.
println("Print everytime the class is instantiated")
//Auxillary Constructor
def this ( name : String){ //First Line has to be primary constructor
this(name,100)
println("Hello Auxillary Constructor")
//this(name,100)
}
def test() : Unit = {
println("Test Mesaage "+name +rollno)
}
}
object HelloWorld {
def main(args: Array[String]) {
val m = new MyClass("kedar",1) //m is an instance
m.test()
println(m.name)
println(m.rollno)
val n = new MyClass("Sugyani") //n is an instance
n.test()
}
}
object HelloWorld {
def main(args: Array[String]) {
println("Hello, world!")
}
/**
* given a Seq[A] and a function f : A => B, return a Seq[B]
*/
def unknown[A, B](as: Seq[A], fn: A => B): Seq[B] = as.map(fn(_))
}