Interview questions for OOP and SOP

1. What is the difference between OOP and SOP?

Object-Oriented Programming Structural Programming
Object-Oriented Programming is a type of programming which is based on objects rather than just functions and procedures Provides logical structure to a program where programs are divided functions
Bottom-up approach Top-down approach
Provides data hiding Does not provide data hiding
Can solve problems of any complexity Can solve moderate problems
Code can be reused thereby reducing redundancy Does not support code reusability.

2. Tell me the key features of object-oriented programming?

The main features are:
• Data Abstraction
• Inheritance
• Encapsulation
• Polymorphism

3. What is Encapsulation?

Encapsulation is an OOPs concept to create and define the restrictions and permissions of an object and its member variable and methods. It is very simple to explain the concept is to make the member variables of a class private and providing public getter and setter methods.

4. What is Polymorphism?

Polymorphism is an instance of something in various forms. Java supports multiple forms of polymorphism like polymorphic method, polymorphic reference variable, polymorphic return types and polymorphic argument types.

5. Why use OOPs?

• OOPs allows clarity in programming thereby allowing simplicity in solving complex problems
• Code can be reused through inheritance thereby reducing redundancy
• Data and code are bound together by encapsulation
• OOPs allows data hiding, therefore, private data is kept confidential
• Problems can be divided into different parts making it simple to solve
• The concept of polymorphism gives flexibility to the program by allowing the entities to have multiple forms

6. What is an object, method and class?

Object: An object is an instance of a class. It has its own identity and behaviour.
Class: Class is a user-defined data type that contains variables, properties and methods. It determines the properties of an object.
Method: It is a set of instructions also called a procedure that is to be performed on the given data

7. What are the main features of OOPs?

• Inheritance
• Encapsulation
• Polymorphism
• Data Abstraction

8. What is an object?

An object is a real-world entity which is the basic unit of OOPs for example chair, cat, dog, etc. Different objects have different states or attributes, and behaviors.

9. What is an abstract class?

An abstract class cannot be proved. Formation of an object is not possible with an abstract class, but it can be inherited. An abstract class can only contain an abstract method, and java allows only abstract method in abstract class while other languages allow non- abstract method as well.

10. How to achieve data abstraction?

Data abstraction can be achieved through:
• Abstract method
• Abstract class

11. Explain virtual functions?

Virtual functions are functions that are there in the close relative class and are overridden by the subclass. These functions are used to accomplish runtime polymorphism.

12. What is a class?

A class is a prototype that consists of objects in different states and with different behaviors. It has a number of methods that are common the objects present within that class.

13. What do you mean by a friend function?

A friend function is a companion of a class that is permitted to access the private and protected data in that same class. A friend can be declared anywhere in the class. A friend function can be:
• A method of another class
• A global function

14. What is the ternary operator?

The ternary operator is an operator which takes three operands. Operands and results are of diverse data types, and it depends on the function. The ternary operator is also known as a conditional operator.

15. What is an exception?

An exception is a kind of notification that interrupts the normal execution of a program. Exceptions provide a pattern to the error and transfer the error to the exception handler to resolve it. The state of the program is saved as soon as an exception is raised.

16. What is a try/ catch block?

A try/ catch block is used to handle exceptions. The try block defines a set of statements that may lead to an error. The catch block basically catches the exception.

17. What is a finally block?

A finally block consists of code that is used to execute important code such as closing a connection, etc. This block executes when the try block exits. It also makes sure that finally block executes even in case some unexpected exception is encountered.

18. Differentiate between an abstract class and an interface?

Basis for comparison Abstract Class Interface
Methods Can have abstract as well as other methods Only abstract methods
Final Variables May contain final and non-final variables Variables declared are final by default
Accessibility of Data Members Can be private, public, etc Public by default
Implementation Can provide the implementation of an interface Cannot provide the implementation of an abstract class

19. What is the difference between a class and a structure?

Class: User-defined blueprint from which objects are created. It consists of methods or set of instructions that are to be performed on the objects.
Structure: A structure is basically a user-defined collection of variables which are of different data types.

20. What is a finally block?

A finally block consists of code that is used to execute important code such as closing a connection, etc. This block executes when the try block exits. It also makes sure that finally block executes even in case some unexpected exception is encountered.

21. Which keyword can be used for overloading?

“operator” keyword is utilised for overloading.

22. Which OOPs concept is used as a reuse mechanism?

Inheritance is the OOPS concept that can be used as a reuse mechanism.

23. Explain method overriding?

When a subclass declares a method possessing similar arguments as a method declared by one of its superclass, method overriding takes place. Using this technique, the behaviour specific to a particular subclass can be defined, The methods marked public, final or static can not be overridden.

24. What is friend function?

• Friend function is a friend of a class.

• It is allowed to access Public, private or protected data of that class.

• It can be declared anywhere in the class declaration.

• It doesn’t have any effect of access control keywords like private, public or protected.

leave your comment

Your email address will not be published. Required fields are marked *