GIGO: words unreadable aloud
Mishrogo Weedapeval
 

 

  Friday 4 June 2004
Chapter 5, Exercises 1-2

Chapter 5, Exercise 1

1. Write a program that creates an ArrayList object without explicitly importing java.util.*.

object c5x1 {
    def main ( args: Array[String] ) = {
        var ar : java.util.ArrayList = _;
    }
}

Chapter 5, Exercise 2

2. In the section labeled "package: the library unit", turn the code fragments concerning mypackage into a compiling and running set of Java files.

Well, s/Java/Scala/...

Choice (a) is simply to refer to MyClass with a qualified reference:

c5x2a.scala:

package x;
object c5x2a {
    def main ( args: Array[String] ) = {
        var m = new mypackage.MyClass();
    }
}

Choice (b) is to import MyClass from its package:

c5x2b.scala:

package x;
import mypackage._;
object c5x2b {
    def main ( args: Array[String] ) = {
        var m = new MyClass();
    }
}

Both of them refer to

c5x2z.scala:

package mypackage;
class MyClass { }

10:41:01 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:15 .
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