murachs_php_4E_chapter14

rtf

School

Southern Illinois University, Carbondale *

*We aren’t endorsed by this school

Course

405

Subject

Computer Science

Date

Nov 24, 2024

Type

rtf

Pages

6

Uploaded by dustinmyers

Report
Chapter 14: How to create and use objects Murach's PHP and MySQL (4th Ed.) MULTIPLE CHOICE 1. A/an ________________ defines the methods and properties of an object. a. class c. enum b. object d. interface ANS: A 2. A/an ________________ is a special method within a class that is executed when a new object is created from the class. a. enum c. constructor b. interface d. destructor ANS: C 3. A method is a/an ________________ that’s coded within a class. a. conditional expression c. function b. arithmetic expression d. control statement ANS: C 4. You can use the ________________ variable within a class to refer to the current object that has been created from the class. a. $current c. $this b. $me d. $_THIS ANS: C 5. To create an object from a class, you code the ________________ keyword followed by the class name and an argument list. a. create c. this b. new d. none of these ANS: B 6. To call one of the methods for an object, you code the object name followed by ________________ and the method name. a. object accessor c. method accessor b. object access modifier d. method access modifier ANS: B 7. A static property or method is one that belongs to a/an ________________ a. class c. enum b. object d. interface ANS: A
8. When you start a new class from a parent class, you can ________________ a method of the parent class by providing your own version of the method. a. derive c. instantiate b. abstract d. override ANS: D 9. To prevent other classes from directly accessing the properties of a class, you can code them as private. Then, to make them available to other classes, you can code a. private methods to set and get their values b. public methods to set and get their values c. a constructor to set and get their values d. a destructor to set and get their values ANS: B 10. When you use inheritance to create a new class from an existing class, the new class starts with the ____________ properties and methods of the existing class. a. private d. all of these b. public e. b and c only c. protected ANS: E 11. When you use object-oriented techniques to implement the MVC pattern, the methods of the model return the data as either arrays or a. classes b. objects c. properties d. result sets ANS: B 12. When a new class extends a superclass, it inherits the properties and methods of the superclass. Then, it can a. override the inherited properties b. override the inherited methods c. delete any of the inheritied properties d. delete any of the inherited methods ANS: B 13. To code a constructor for a class named Cart that requires two arguments, you can start with this code: a. public function Cart($arg1, $arg2) { b. public function __construct($arg1, $arg2) { c. private function Cart($arg1, $arg2) { d. private function __construct($arg1, $arg2) { ANS: B 14. To create an object from a class named Cart that requires two arguments, you code a. new Cart($arg1, $arg2)
b. new Cart(arg1, arg2) c. Cart_constructor($arg1, $arg2) d. Cart_constructor(arg1, arg2) ANS: A 15. By default, the properties of a PHP class are ____________. a. private c. public b. protected d. anonymous ANS: C 16. A subclass can ____________ the superclass by adding new properties and methods. a. destruct c. clone b. extend d. create ANS: B 17. To code a method within a class that sets the value for a private property named $name based on the argument that’s passed to it, you start with this code: a. public function setName() { b. public function setName($value) { c. private function setName() { d. private function setName($value) { ANS: B 18. To refer to a public property named categoryName for an object that’s referenced by $category, you code a. $category->categoryName b. $category->$categoryName c. $category::categoryName d. $category::$categoryName ANS: A 19. ______________ properties and methods are inherited by a sublass but not accessible outside of the class. a. Protected c. Private b. Public d. Read only ANS: A 20. Which PHP function can be used to check if a specified class has been defined? a. get_class() c. class_exists() b. is_a() d. property_exists() ANS: C 21. To call a static method named randomize() in a class named Cart, you code a. Cart->randomize() b. Cart->$randomize() c. Cart::randomize()
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
d. Cart::$randomize() ANS: C 22. Which of the following are variables that store the data for a class? a. methods c. destructors b. properties d. brackets ANS: B 23. ________________ provides a way to create a new class based on an existing class. a. Overriding c. Portability b. Inheritance d. Chaining ANS: B 24. A fundamental concept of object-oriented programming that groups related data and functionality in a class is called ____________________. a. encapsulation c. inheritance b. portability d. normalization ANS: A 25. Which type of property in a class can be directly accessed by code outside of the class? a. public c. protected b. private d. imaginary ANS: A 26. Which of the following is a special method executed when a new object is created from a class? a. constructor c. inheritor b. destructor d. encapsulator ANS: A 27. Which of the following is a term that describes the process of creating an object from a class? a. instantiation c. refactoring b. destructing d. inheriting ANS: A 28. Which PHP function can be used to determine if an object is an instance of a class? a. is_a() c. get_class() b. class_exists() d. check_instance() ANS: A 29. Given this property: private readonly int $id; which of the following is true? a. the value of the property can only be set once b. the value of the property can only be set within the constructor method
c. the value of the property can only be set within a regular method d. the value of the property can be set multiple times within the class ANS: A 30. What feature that was introduced with PHP 8.0 lets you define and initialize properties from the parameter list of the constructor? a. constructor parameter promotion c. constructor property promotion b. constructor parameter conversion d. constructor property conversion ANS: C 31. To generate a property from a parameter of a constructor you must a. include a type declaration for the parameter b. include an access modifier for the parameter c. include the readonly keyword for the parameter d. all of these ANS: B 32. To prevent an error from occurring when you use object chaining on a null object, you can use the ____________ operator. a. ifnull c. nullsafe b. null coalescing d. notnull ANS: C 33. With PHP 8.1, you can use a/an ____________ to create a custom type that defines a set of fixed values. a. enum c. object chain b. abstract class d. concrete class ANS: A Code example 14-1 enum Vehicle { case SportsCar; case Sedan; case SUV; case Truck; } 34. (Refer to code example 14-1) Which of the following statements creates an instance of the enum for the SportsCar case? a. $vehicle = Vehicle->SportsCar; c. $vehicle = Vehicle(SportsCar); b. $vehicle = Vehicle::SportsCar; d. $vehicle = Vehicle(0); ANS: B 35. (Refer to code example 14-1) Given a variable named $vehicle that contains an instance of the Vehicle enum and this class that includes a private property for the Vehicle enum: class Owner { private Vehicle $vehicle;
public function getVehicle() { return $this->vehicle; } public function setVehicle(Vehicle $vehicle) { $this->vehicle = $vehicle; } } what code would you use to set the value of the enum in the class? a. $owner = new Owner($vehicle); c. $owner = new Owner(); $owner->setVehicle($vehicle); b. $owner = new Owner(); $owner->setVehicle::$vehicle; d. $owner = new Owner(); $owner = setVehicle::$vehicle; ANS: C 36. To create a class that can’t be inherited by a subclass, you include the ____________ keyword on the class declaration. a. noinherit c. last b. fixed d. final ANS: D 37. PHP 8.1 provides for the ________________ type, which requires that a function parameter or return value be an object that implements all of the specified interfaces. a. union c. intersection b. combination d. correlation ANS: C
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help