creating an object outside method

From: coltrane (tendengarci_at_yahoo.com)
Date: 03/30/05


Date: 30 Mar 2005 05:25:06 -0800

There are 2 different places a class member can be instantiated, at the
class level of within a method :

>>
class MyClass {
    AClass ac = new AClass(); // instantiated at class level
    YetAnotherClass yac;

    void someMethod(){
        yac = new YetAnotherClass(); // instantiated with a method
    }
}
>>

Are there an reasons I would choose one over the other?
Also, what if the class object was static?

thanks for your help

john



Relevant Pages

  • Associative Array in Class
    ... In PHP Version 4.3.6 I am trying get a value from a class member that ... is an associative array... ... class MyClass ... function MyClass() ...
    (php.general)
  • Associative Array In Class
    ... In PHP Version 4.3.6 I am trying get a value from a class member that ... is an associative array... ... class MyClass ... function MyClass() ...
    (comp.lang.php)