What will be the output of the following PHP code?
<?php
class ShopProductWriter
{
public function write($shopProduct)
{
$str = "{$shopProduct->title}: " .$shopProduct->getProducer() ." ({$shopProduct->price})n";
print $str;
}
}
$product1 = new ShopProduct( "My Antonia", "Willa", "Cather", 5.99 );
$writer = new ShopProductWriter();
$writer->write( $product1 );
?>
<?php
class ShopProductWriter
{
public function write($shopProduct)
{
$str = "{$shopProduct->title}: " .$shopProduct->getProducer() ." ({$shopProduct->price})n";
print $str;
}
}
$product1 = new ShopProduct( "My Antonia", "Willa", "Cather", 5.99 );
$writer = new ShopProductWriter();
$writer->write( $product1 );
?>
A. Error
B. Cather: Willa My Antonia (5.99)
C. Willa: Cather My Antonia (5.99)
D. My Antonia: Willa Cather (5.99)
Answer: Option D
Related Questions on Object Oriented Concept
Which one of the following is not a valid class name?
A. ShopProduct
B. Shopproduct
C. Shopproduct1
D. 1shopproduct
Fill in the blank with the best option. An Object is a/an ________ of a class.
A. type
B. prototype
C. instance
D. object
Which version of PHP introduced the visibility keywords i.e public, private, and protected?
A. PHP 4
B. PHP 5
C. PHP 5.1
D. PHP 5.3
Join The Discussion