0% found this document useful (0 votes)
27 views

OOPs_Interview_Questions

The document provides a comprehensive overview of Object-Oriented Programming (OOP) concepts, including definitions of key terms such as classes, objects, encapsulation, abstraction, polymorphism, and inheritance. It outlines the advantages and disadvantages of OOP, compares it with structured programming, and discusses various programming languages that utilize OOP principles. Additionally, it covers constructors, destructors, interfaces, and the differences between abstract classes and interfaces.

Uploaded by

pranayaws15
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

OOPs_Interview_Questions

The document provides a comprehensive overview of Object-Oriented Programming (OOP) concepts, including definitions of key terms such as classes, objects, encapsulation, abstraction, polymorphism, and inheritance. It outlines the advantages and disadvantages of OOP, compares it with structured programming, and discusses various programming languages that utilize OOP principles. Additionally, it covers constructors, destructors, interfaces, and the differences between abstract classes and interfaces.

Uploaded by

pranayaws15
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Object-Oriented Programming (OOPs) Interview Questions and Answers

1. 1. What is Object-Oriented Programming (OOPs)?

OOP is a programming paradigm where software is organized as a collection of objects


interacting with each other. An object contains data (attributes) and methods (functions) to
operate on that data.

2. 2. Why OOPs?

Advantages of OOPs:
- Better Code Reusability: Through inheritance and polymorphism.
- Easier Maintenance: Encapsulation allows easy updates.
- Improved Data Security: Data hiding restricts unauthorized access.
- Better for Large Software: Logical organization with classes and objects.

3. 3. What is a Class?

A class is a blueprint or template for creating objects. It defines data members (variables)
and methods (functions).

4. 4. What is an Object?

An object is an instance of a class. It has a state (data) and behavior (methods).

5. 5. What are the main features of OOPs?

- Encapsulation
- Abstraction
- Polymorphism
- Inheritance

6. 6. What is Encapsulation?

Encapsulation is the bundling of data and methods into a single unit (class) and restricting
access using access modifiers like private, protected, and public.

7. 7. What is Abstraction?

Abstraction is hiding unnecessary details and showing only the relevant features to the
user. Achieved using abstract classes and interfaces.

8. 8. What is Polymorphism?

Polymorphism means 'many forms'. It allows methods to perform different tasks based on
the context.
- Compile-time Polymorphism: Method Overloading.
- Runtime Polymorphism: Method Overriding.

9. 9. What is Inheritance?

Inheritance allows a class (child) to use the properties and methods of another class
(parent). It promotes code reusability.

10. 10. What are Access Specifiers?

Access specifiers control access to members of a class.


- Public: Accessible everywhere.
- Private: Accessible only within the class.
- Protected: Accessible within the class and subclasses.

11. 11. Advantages and Disadvantages of OOPs

Advantages:
- Code reusability.
- Easier maintenance and updates.
- Better data security.

Disadvantages:
- Requires skilled programmers.
- Not suitable for all problems.
- Larger program size compared to procedural programming.

12. 12. Other Programming Paradigms

- Imperative Paradigm: Procedural and Object-Oriented Programming.


- Declarative Paradigm: Functional and Logical Programming.

13. 13. Difference Between Structured and Object-Oriented Programming

| OOPs | Structured Programming |


|-----------------------------|---------------------------------|
| Based on objects. | Based on functions. |
| Bottom-up approach. | Top-down approach. |
| Data-focused. | Code-focused. |

14. 14. Commonly Used OOP Languages

- Java
- C++
- Python
- C#
- Ruby
15. 15. Types of Polymorphism

1. Compile-Time Polymorphism: Achieved using method overloading.


2. Runtime Polymorphism: Achieved using method overriding.

16. 16. Difference Between Overloading and Overriding

- Overloading: Multiple methods with the same name but different parameters.
- Overriding: Redefining a method in a child class.

17. 17. Limitations of Inheritance

- Can lead to tightly coupled classes.


- Difficult to implement correctly.
- Increases processing time.

18. 18. Types of Inheritance

1. Single: One parent, one child.


2. Multiple: Multiple parents (not supported in Java).
3. Multilevel: Child inherits from another child class.
4. Hierarchical: Multiple children inherit from one parent.
5. Hybrid: Combination of inheritance types.

19. 19. What is an Interface?

An interface is a blueprint for a class that contains method declarations without


implementation.

20. 20. Difference Between Abstract Class and Interface

| Abstract Class | Interface |


|-----------------------------|----------------------------|
| Can have abstract and concrete methods. | Only abstract methods (until Java 8). |
| Supports single inheritance. | Supports multiple inheritance. |

21. 21. How much memory does a class occupy?

A class doesn’t occupy memory. Only objects created from the class use memory.

22. 22. Is it necessary to create objects from a class?

No. Static methods can be called directly using the class name without creating objects.

23. 23. Difference Between Structure and Class (C++)

- Structure: Members are public by default.


- Class: Members are private by default.
24. 24. What is a Constructor?

A constructor initializes objects. It has the same name as the class and no return type.

25. 25. Types of Constructors

1. Default Constructor: No arguments.


2. Parameterized Constructor: Accepts arguments.
3. Copy Constructor: Initializes using another object (not in Java).

26. 26. What is a Destructor?

A destructor cleans up resources when an object is destroyed.


- Java: Uses garbage collection, no explicit destructor.

27. 27. Can we overload a constructor in Java?

Yes, constructors can be overloaded by changing the number or type of parameters.

28. 28. Can we overload a destructor in Java?

No, destructors cannot be overloaded.

29. 29. What is a Virtual Function?

A function that can be overridden in a subclass.


- In Java, all non-static, non-final methods are virtual by default.

30. 30. What is a Pure Virtual Function?

A method with no body that must be implemented in a subclass.


Example:
```java
abstract class Shape {
abstract void draw();
}
```

31. 31. What is an Abstract Class?

An abstract class cannot be instantiated and may contain both abstract and non-abstract
methods.
Example:
```java
abstract class Animal {
abstract void sound();
void eat() { System.out.println("Eating..."); }
}
```

You might also like