PHP面向对象-测试题(1~5)

    1. What is the construct used to define the blueprint of an object called?
    Your Answer: ____________________________
    2. At the end of the execution of the following script, which values will be stored in the $a->my_value array? (Choose 3)
    <?php
    class my_class
    {
    var $my_value = array();
    function my_class ($value)
    {
    $this->my_value[] = $value;
    }
    function set_value ($value)
    {
    $this->$my_value= $value;
    }
    }
    $a = new my_class ('a');
    $a->my_value[] = 'b';
    $a->set_value ('c');
    $a->my_class('d');
    ?>
    A. c
    B. b
    C. a
    D. d
    E. e
    3. How can you write a class so that some of its properties cannot be accessed from outside its methods?
    A. By declaring the class as private
    B. By declaring the methods as private
    C. It cannot be done
    D. By writing a property overloading method
    4. Which object-oriented pattern would you use to implement a class that must be instantiated only once for the entire lifespan of a script?
    A. Model-view-controller
    B. Abstract factory
    C. Singleton
    D. Proxy
    E. State
    5. A class can be built as an extension of other classes using a process known as inheritance. In PHP, how many parents can a child class inherit from?
    A. One
    B. Two
    C. Depends on system resources
    D. Three
    E. As many as needed

你可能感兴趣的:(PHP,properties,测试,Class,extension,overloading)