Subjects

All subjects Django Java Python React Spring Boot JavaScript PHP
Sign Up Free
Interview question

What is the difference between a class and an object in PHP? PHP में class और object में क्या अंतर है?

Answer

A class is a blueprint or template that defines properties and methods. An object is a concrete instance created from that blueprint, with its own actual values in memory.

class Car {
    public string $color;
    public function drive() { return $this->color . ' car is driving'; }
}

$car1 = new Car();
$car1->color = 'Red';

$car2 = new Car();
$car2->color = 'Blue';
AspectClassObject
NatureBlueprint/template, no memory allocated for dataActual instance with allocated memory
CountOne class definitionMany objects can be created from one class
Keywordclassnew

Interview tip: Use the analogy: class is the architectural blueprint of a house, an object is an actual house built from it - many houses (objects), one blueprint (class).

Class एक blueprint या template है जो properties और methods डिफाइन करता है। Object उस blueprint से बना असली instance है, जिसकी अपनी वैल्यूज़ memory में होती हैं।

class Car {
    public string $color;
    public function drive() { return $this->color . ' car is driving'; }
}

$car1 = new Car();
$car1->color = 'Red';

$car2 = new Car();
$car2->color = 'Blue';
पहलूClassObject
प्रकृतिBlueprint/template, डेटा के लिए memory allocate नहीं होतीअसली instance, memory allocated
संख्याएक class definitionएक class से कई objects बन सकते हैं
कीवर्डclassnew

इंटरव्यू टिप: यह analogy इस्तेमाल करें: class घर का architectural blueprint है, object उससे बना असली घर - कई घर (objects), एक blueprint (class)।

Was this answer clear?