Objects Concept in Opps – PHP
In Oops Class and objects are a very important topic, So on this page, you will learn about the object. how the object is created and what is the syntax in PHP.
Objects are also known as instance of classes.
What is Object in Oops with examples?
An individual instance of the data structure is defined by a class. You define a class once and then make many objects that belong to it. Objects are also known as instance.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | <?php class Car { /* Member variables */ var $price; var $color; var $brand; /* Member functions */ function setPrice($car_price){ $this->price = car_price; } /* Member functions */ function getPrice(){ echo $this->price; } /* Member functions */ function setColor($car_color){ $this->color = $car_color; } /* Member functions */ function getColor(){ echo $this->color; } /* Member functions */ function setBrand($car_brand){ echo $this->brand=$car_brand; } /* Member functions */ function getBrand(){ echo $this->brand; } } ?> |
How to create an Object
Here you can create an object by using the keyword new.
1 2 3 4 | <?php /* create a new car object */ $carObj = new Car(); ?> |
Questions Asked In Interview About an Object in Oops
- What is an object?
- How we can create an object give one example.?
- What is class?
- In which class Object can not created