By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
Q 1. What is OOPS? OOPS stands for Object Oriented Programming system. It is a programming technique which is used to design your application. In this programs are considered as a collection of objects and each object is an instance of a class.
Q 2. Write the four basic concepts of OOPS.
Inheritance: The procedure in which one class inherits the attributes and methods of another class. Polymorphism: Means having many forms. In OOP it refers to the functions having the same names but carrying different functionalities. Encapsulation: A way to ensure security. Basically, it hides the data from the access of outsiders. Such as if an organization wants to protect an object/information from unwanted access by clients or any unauthorized person then encapsulation is the way to ensure this. Abstraction: Used for for hiding the internal details or implementations of a function and showing its functionalities only.
Q 3. What is class? Class is a user-defined datatype that contains variables, properties, and methods. It defines properties of an Object
Example: class Person{ public $name; function __construct($name){ $this->name = $name; } function getUserDetails(){ return "My name is ".$this->name; } }
Q 4. What is Encapsulation? It is an attribute of an object, and it contains all data which is hidden. That hidden data is restricted to the members of that class.
Q 5. What is Polymorphism? It takes more than one form. It is nothing but assigning behavior or value in a subclass to something that was already declared in the main class.
Q 6. What is Inheritance? It is a technique in which one class acquires the property of another class. With the help of inheritance, we can reuse the fields and methods of the existing class.
Inheritance has three types:
Single inheritance Multiple inheritance Multi level inheritance But PHP supports only single inheritance, where only one class can be derived from single parent class. We can also use multiple inheritance by using interfaces.
Q 7. What is constructor and destructor? Constructor and Destructor both are special functions which are automatically called when an object is created and destroyed.
Example: Constructor
class Animal { public $name = "No-name animal"; public function __construct() { echo "I'm alive!"; } }
Destructor
class Animal { public $name = "No-name animal"; public function __construct($name) { echo "I'm alive!"; $this->name = $name; } public function __destruct() { echo "I'm dead now :("; } } $animal = new Animal("Bob"); echo "Name of the animal: " . $animal->name;
Q 8. What is different types of Visibility? PHP have three access modifiers such as public, private and protected.
public scope of this variable or function is available from anywhere, other classes and instances of the object. private scope of this variable or function is available in its own class only. protected scope of this variable or function is available in all classes that extend current class including the parent class.
Q 9. What is final class and final method? It's properties can not be declared final, only classes and methods may be declared as final. If the class or method defined as final then it cannot be extended.
Example: class childClassname extends parentClassname { protected $numPages; public function __construct($author, $pages) { $this->_author = $author; $this->numPages = $pages; } final public function PageCount() { return $this->numPages; } }
Q 10. What is static keyword? When a variable or function declared as static then it cannot be accessed with an instantiated class object. It is treats as public if no visibility is defined. It can also be used to define static variables and for late static bindings.
Q 11. What are the difference between overloading and overriding in oops? Overloading: It occurs when two or more methods in one class have the same method name but different parameters.
Overriding: It means having two methods with the same method name and parameters. One of the methods is in the parent class and the other is in the child class.
Q 12. What is "this"? It refers to the current object of a class.
Q 13. What are the difference between abstract class and interface in OOPS? Thera are many differences between abstract class and interface in php.
1. Abstract methods can declare with public, private and protected. But in case of Interface methods declared with public. 2. Abstract classes can have constants, members, method stubs and defined methods, but interfaces can only have constants and methods stubs. 3. Abstract classes doest not support multiple inheritance but interface support this. 4. Abstract classes can contain constructors but interface doest not support constructors.
Q 14. What is namespace in PHP? It allows us to use the same function or class name in different parts of the same program without causing a name collision.
namespace MyAPP; function output() { echo 'IOS!'; } namespace MyNeWAPP; function output(){ echo 'RSS!'; }
Q 15. What is traits? How it is used in php? Traits is a group of methods that reuse in single inheritance. A Trait is intended to reduce some limitations of single inheritance by enabling a developer to reuse sets of methods.
Example: trait HelloWorld { use Hello, World; } class MyWorld { use HelloWorld; } $world = new MyWorld(); echo $world->sayHello() . " " . $world->sayWorld(); //Hello World
Q 16. What are the advantages of OOPS in PHP? Code Resusability Flexibility Maintainability Security Testability
Q 17. What is member variable? Member variables defined inside a class. Data of member variables will be invisible to the outside of the class and can be accessed via member functions. These variables are called attribute of the object once an object is created.
Q 18. What is member function? Member function defined inside a class and are used to access object data.
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.