Name: Apple. * Color: Red.
slut
Name: Banana. * Color: Yellow.
slut
Example Explained
- The Fruit class is defined with two properties: $name and $color.
- The __construct() method initializes the properties when a new object of the Fruit class is created, using the provided values.
- The get_details() method is defined to print out the fruit's name and color.
- A new object $apple is created from the Fruit class, and values ("Apple", "Red") are passed to the constructor.
- A new object $banana is created from the Fruit class, and values ("Banana", "Yellow") are passed to the constructor.
- The get_details() method is called on the $apple and $banana objects to display the details of the fruit.