Hi Raj,
Sorry for this chain of mails but thought i'd share something.
Now when you read the scala book i thought traits are similar to classes
(pg:245)
But actually traits are Interfaces
trait trait1 {
def philosophize() {
println("I consume memory, therefore I am!")
}
}
//trait a
aven...@linux-fksn:~> javap -private trait1$class
Compiled from "trait1.scala"
public *interface* trait1 extends scala.ScalaObject{
public abstract void philosophize();
}
and when they run they create a class which implements that interface
aven...@linux-fksn:~> javap -private trait1$class.class
Compiled from "trait1.scala"
public *abstract class* trait1$class extends java.lang.Object{
public static void $init$(trait1);
public static void philosophize(trait1);
}
Now
class sms extends trait1{
}
//class b extends a
aven...@linux-fksn:~> javap -private sms
Compiled from "sms.scala"
public class sms extends java.lang.Object* implements*trait1,scala.ScalaObject{
public sms();
public int $tag() throws java.rmi.RemoteException;
public void philosophize();
Now i create an object
object k{
def main(args:Array[String]){
val c:trait1=new sms
c.philosophize
}
}
-->"I consume memory therefore i am"
//val c:a=new b
Now
class sms extends trait1{
override def philosophize{
println("I don't use memory")
}
}
Now when you run k object you get
-->"I don't use memory"
As far as your query is concerned the previous post may help you out!!!
thanks,
SMS
[Non-text portions of this message have been removed]