GIGO: words unreadable aloud
Mishrogo Weedapeval
 

 

  Tuesday 20 July 2004
Chapter 6, Exercise 10

Skipping forward a ways -- the next few exercises modify some classes that Bruce provided in the chapter, and some depend on Java's ability to have classes that lack default constructors, which I think is something you can't do in Scala. Anyway: 10. Create a class called Root that contains an instance of each of the classes (that you also create) named Component1, Component2, and Component3. Derive a class Stem from Root that also contains an instance of each component. All classes should have default constructors that print a message about that class. Well, OK, but I think I'll call them P, Q, and R instead.

package x; 
class P { W.rn( "P" ); }
class Q { W.rn( "Q" ); }
class R { W.rn( "R" ); }
class Root {
    val rpm = new P;
    var rqm = new Q;
    var rrm = new R;
    W.rn( "Root" );
}
class Stem extends Root {
    val spm = new P;
    var sqm = new Q;
    var srm = new R;
    W.rn( "Stem" );
}
object c6x10 {
    def main ( args : Array[String] ) = {
        var main_R = new Root;
        val main_S = new Stem;
    }
}

Here's the output that I get:

P
Q
R
Root
P
Q
R
Root
P
Q
R
Stem

I'll skip 11 and 12, and investigate overloading next.
11:58:13 PM   comment/     



Click here to visit the Radio UserLand website. Click to see the XML version of this web page. © Copyright 2007 Doug Landauer .
Last update: 07/2/6; 12:41:27 .
Click here to send an email to the editor of this weblog.

July 2004
Sun Mon Tue Wed Thu Fri Sat
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Jun   Aug

Previous/Next