GIGO: words unreadable aloud
Mishrogo Weedapeval
 

 

  Friday 9 July 2004
Chapter 6, Exercise 1

Create two classes, A and B, with default constructors (empty argument lists) that announce themselves. Create a new class called C that inherits from A, and create a member of class B inside C. Do not create a constructor for C. Create an object of class C and observe the results.

package x;
class A { W.rn( "A constructor called" ); } 
class B { W.rn( "B constructor called" ); }
class C extends A { val obj_b = new B(); }
object c6x1 {
    def main ( args : Array[String] ) = {
        val obj_c = new C();
    }
}

Output

A constructor called
B constructor called

7:36:45 AM   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:58 .
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