Challenge: Build a Simple Class
Recap: Building a PHP Class
- Class: Blueprint for objects;
- Properties: Variables that store object data;
- Methods: Functions that define object behavior;
- Constructor: Initializes properties when an object is created.
Use these concepts to complete the exercise below.
Oppgave
Swipe to start coding
Write a PHP class named Book that models a book with a title and an author. Your class should have:
- Properties to store the title and author.
- A constructor that sets the title and author properties using the provided arguments.
- A method called
displayInfothat outputs the book's title and author in the format:Title: [title], Author: [author].
Løsning
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 1. Kapittel 5
single
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår
Fantastisk!
Completion rate forbedret til 6.67
Challenge: Build a Simple Class
Sveip for å vise menyen
Recap: Building a PHP Class
- Class: Blueprint for objects;
- Properties: Variables that store object data;
- Methods: Functions that define object behavior;
- Constructor: Initializes properties when an object is created.
Use these concepts to complete the exercise below.
Oppgave
Swipe to start coding
Write a PHP class named Book that models a book with a title and an author. Your class should have:
- Properties to store the title and author.
- A constructor that sets the title and author properties using the provided arguments.
- A method called
displayInfothat outputs the book's title and author in the format:Title: [title], Author: [author].
Løsning
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 1. Kapittel 5
single