OOPS interview questions and Answers

04 Jan 2023, 21 Questions

OOPS, i.e. Object-Oriented Programming Language is one of the most important concepts which is widely used in the programming world. Every interview that you are attending today requires the knowledge of OOPS. The below article compiles the most frequently asked OOPS Interview Questions and Answers which help you to ace your interviews. If you don’t know object-oriented programming then you can’t think of developing mobile software. Its unique features like inheritance, data hiding which is also known as encapsulation, data binding, polymorphism make it superior to other programming languages.

Popular languages like Java, C++, and Python, etc. are using the concept of the oops model and making it more significant in the programming world. Through OOPs a user can break his program into small-sized problems and that can be solved easily like one object at one time. The system in which the concept of OOP is used can be easily upgraded and hence provides better quality of software, enhances programmer productivity, and lower maintenance cost.

Object Oriented Programming Interview Questions

Here in this article, we will be listing frequently asked OOPS interview questions and Answers with the belief that they will be helpful for you to gain higher marks. Also, to let you know that this article has been written under the guidance of industry professionals and covered all the current competencies.

Q2. What is Class and Objects in OOPS?


In Object-Oriented Programming, a class is a blueprint that defines the functions and variables which are common to objects of a certain kind.


In OOPS an object is a specimen of the class. It is nothing but a component that consists of methods and properties which make the data useful and help users to determine the behavior of the class.

lead interview questions
Let’s understand this with an example

class Person{

    public $name;

    function __construct($name){

        $this->name = $name;


    function getUserDetails(){

        return "My name is ".$this->name;



22 1
Q3. What are the types of Class Variables?

We have three different types of Class Variables in OOPs.

1. Local Variables

These types of variables are declared locally in methods, blocks, and constructors. These variables are created when program control enters the methods, blocks, and constructor and are destroyed once program control leaves them.

2. Instance Variables

These variables are declared outside a block, constructor, or method. These are created once a class object is created and destroyed when the object is destroyed.

3. Static Variables

Static variables are also called class variables and are defined using the static keyword. These are declared within a class but outside a code block and a method. The creation of these variables starts when the program starts and is destroyed when the program ends.

5 0
Q4. What is the difference between Method overriding and Method overloading?
Method Overloading Method Overriding
It is the concept where we define two or more methods by the same name but with different signatures. In method overriding we define two or more identical methods which have the same name and signatures.
The binding of the method is done at compile time. The binding of the method is done at run time.
There are no class restrictions i.e. it can be achieved in the same or different classes. There are class restrictions in it i.e. it can only be achieved in different classes.
3 1
Q5. What is virtual and pure virtual function?
Virtual Function Pure Virtual Function
Virtual Function has its definition hidden in the Base class They have no definition in the Base class.
The derived class can override the virtual function if required. In the case of a pure virtual function, the derived class has to override it.
If the derived class fails to override then it has the option to use the virtual function of the base class It will throw a compilation error if it fails to override pure virtual function.
2 0
Q6. List out some of the differences between a class and an object?
It is a blueprint from which different instances (objects) are created. Objects are the instances of the class.
Class is a logical entity. Objects are physical entities.
Users can declare class only once. Objects can be declared multiple times depending upon the requirements.
When a class is created there is no memory allocation Objects allocated memory.
Class is a group of objects. Objects are real-world entities such as pen, copy, mouse, etc.
Class can be declared using class keyword e.g class Student {} Objects can be declared using the new keyword e.g. Student s1=new Student();
3 0
Q7. What are the main features of OOPs?

You have to list these four features of OOPs while answering this question-

  • Inheritance
  • Polymorphism
  • Encapsulation
  • Data Abstraction
42 3
Q8. What is Encapsulation in oops with an example?

The process of binding up data and functions together that manipulates them is known as encapsulation in OOPS. It protects the data from outside interference and misuse.

Let’s understand the concept of encapsulation with both real-world examples and with the help of a program.

lead interview questions
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.

class Account {
    private int account_number;
    private int account_balance;

    public void show Data() {
        //code to show data

    public void deposit(int a) {
        if (a < 0) {
            //show error
        } else
            account_balance = account_balance + a;

28 16
Q9. What is Polymorphism and its types in OOPS?

Polymorphism is one of the core concepts which is used in object-oriented programming. Polymorphism generally shows the relationships between parent class objects and child class objects.

Types of polymorphism in OOPs

  • Compile Time Polymorphism- It is also known as Static Binding and allows the programmer to implement various methods. Names can be the same but their parameters should be different.
  • Runtime Polymorphism- It is also known as Dynamic Binding and allows the programmer to call a single overridden method during the runtime of the program.
64 5
Q10. 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 type, are given below.

  • 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.

15 2
Q11. What is constructor and destructor?

Constructor and Destructor both are special functions which are automatically called when an object is created and destroyed.



class Animal


     public $name = "No-name animal";

     public function __construct() {

     echo "I'm alive!";




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;


7 6
Q12. 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.
15 1
Q13. What are the Final class and Final methods?

Final Class- A class that can’t be extended and inherited further is known as Final Class. This class is declared with the keyword final and should be declared.

Final Method- Methods in the final class are implicitly final and if a user uses the final keyword that means methods can’t be overridden by subclasses.


class childClassname extends parentClassname {
    protected $numPages;

    public function __construct($author, $pages) {
        $this->_author = $author;
        $this->numPages = $pages;

    final public function PageCount() {
        return $this->numPages;

6 8
Q14. 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.
6 1
Q15. 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.

11 0
Q16. What is "this"?

It refers to the current object of a class.

7 0
Q17. 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.

6 4
Q18. 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!';


6 3
Q19. 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.


trait HelloWorld


use Hello, World;


class MyWorld {

use HelloWorld;


$world = new MyWorld();

echo $world->sayHello() . " " . $world->sayWorld(); //Hello World

4 1
Q20. What are the advantages of OOPS in PHP?
  • Code Resusability
  • Flexibility
  • Maintainability
  • Security
  • Testability
4 1
Q21. What is member function?

Member function defined inside a class and are used to access object data.

6 1


Object-Oriented Programming is a very vast concept and takes some time to master. Going only through these object-oriented programming interview questions won't help you. You have to brush up your mind by practicing more and more programming questions to keep you updated and to get a better understanding of OOPS concepts.

Let me give you a short and smart trick to crack these types of interviews. Whenever you look at any real entities try to relate them with the OOPS concept and try to find their methods, attributes. In this way, programming is more enjoyable and easier.

About Best Interview Question
Best Interview Question
Technical Consultant

With our 10+ experience in PHP, MySQL, React, Python & more our technical consulting firm has received the privilege of working with top projects, 100 and still counting. Our team of 25+ is skilled in distinct programming languages such as Python, Java, React.js, Angular, Node.js, PHP, HTML, CSS, Designing, iOS and Android apps, Database, .net, QA, Digital Marketing and Govt. jobs, etc. We are helping 10+ companies in solving their technical problems. When not found coding, our technical consultants can be seen helping out others.