GIGO: words unreadable aloud
Mishrogo Weedapeval
 

 

  Wednesday 9 June 2004
Chapter 5, Exercise 6

Bruce suggests that we "Create a class with protected data. Create a second class in the same file with a method that manipulates the protected data in the first class."

package x;
class c5x6_parent {
    protected var pd = 12;
}
class c5x6_child extends c5x6_parent {
    def seeSet ( npd: Int ) : Int = {
        val res = this.pd;
        this.pd = npd;
        res
    }
}
object c5x6 {
    def main ( args: Array[String] ) = {
        val z = new c5x6_child;
        Console.println( z.seeSet( 42 ) );
        Console.println( z.seeSet( 69 ) );
    }
}

10:02:32 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:40:40 .
Click here to send an email to the editor of this weblog.

June 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      
May   Jul

Previous/Next