What's new
  • Welcome to PHCorner forums. Take a moment to sign up and gain unlimited access and extra privileges that guests are not entitled to, such as: All that and more! Registration is quick, simple and absolutely free. Join our community today!

Help Mga mamaw sa Programming Kailangan ko tulong nyo (PHP)

SyntaXenginE

Elite
Joined
May 11, 2018
Messages
1,354
Reaction
1,003
KAILANGAN KO TULONG NYO MGA PAPS


We will create an Admin class, which is a child class of the User class. Follow and write the equivalent PHP scripts or answer with an explanation from the instructions listed below.


1. Create a user class.

2. Add to the class a private property with the name of $username.

3. Create a setter method that can set the value of the $username.

4. Create a class Admin that inherits the User class.

5. Now, let’s add to the Admin class some code. First, add a public method by the name of expressYourRole, and make it return the string: “Admin”.

6. Add to the Admin class another public method, sayHello, that returns the string “Hello admin, XXX” with the username instead of XXX.

7. Create an object $admin1 out of the class Admin, set its name to “Balthazar”, and sayhello to the user. Do you see any problem?

8. What do you think is the cause of the problem?

9. How will you fix this problem?
 

zeinab01

Established
May nasimulan ka na ba? Kung meron pwede paki share? hahaha kung tinuro na sa nyo mga class, ung pinagpagawa sa inyo pinagsama samang mga example lng ng module :D
 
Comment
PHP:
<?php
class User {
  private $username; // <--- change to public
  public function __construct($username) {
    $this->username = $username;
  }
}

class Admin extends User {
  public function expressYourRole() {
    echo "admin";
  }
 
  public function sayHello() {
    echo "Hello admin, {$this->username}";
  }
}

$Balthazar= new Admin("Balthazar");
$Balthazar->sayHello();
?>

just change the private $username to public para lumabas sya sa sayHello() na function
 
Comment

Online statistics

Members online
744
Guests online
1,799
Total visitors
2,543

Forum statistics

Threads
1,016,280
Messages
17,408,808
Members
1,487,696
Comments
700,172
Attachments
1,145,124
Profile posts
96,502
Top