PBLPHP
PBLPHP
<?php
class Science {
protected $phys;
protected $chem;
class Maths {
protected $geo;
protected $algo;
private $geo;
private $algo;
parent::__construct($phys, $chem);
$this->geo = $geo;
$this->algo = $algo;
// Example usage
$student = new Result(85, 90, 80, 75); // Pass marks for each subject
<?php
class Staff {
protected $code;
}
// Derived class 1: Teacher
private $subject;
private $post;
// Example usage
?>
trait Test {
public $marks1;
public $marks2;
$this->marks1 = $marks1;
$this->marks2 = $marks2;
trait Sports {
public $sports_marks;
$this->sports_marks = $sports_marks;
}
// Derived Class: Result (using multiple traits for Test and Sports)
class Result {
public $total;
$this->marks1 = $marks1;
$this->marks2 = $marks2;
$this->sports_marks = $sports_marks;
}
// Example usage
$studentResult = new Result(85, 90, 80); // Example marks for Test and Sports
?>
// Class definition
class Student {
// Data members
public $roll_no;
public $name;
$this->roll_no = $roll_no;
$this->name = $name;
}
// Method to display the data
$student = new Student(101, "John Doe"); // Initialize with roll number 101 and name "John Doe"
$student->display();
?>
5) Write a php script to declare a class college with name and code. Derive a
new class as student with members or properties as name. Accept and
display details of one student along with college data.
<?php
class College {
// Data members for College class
public $collegeName;
public $collegeCode;
$this->collegeName = $collegeName;
$this->collegeCode = $collegeCode;
public $studentName;
$this->studentName = $studentName;
}
// Method to display student details along with college details
// Call the method from the parent class to display college details
$this->displayCollegeDetails();
$collegeCode = "1234";
$student->displayStudentDetails();
?>