Commonly asked OOPS Interview Questions, Exercises of Object Oriented Programming

Commonly Asked OOP Interview Questions. What is Object Oriented Programming? Object Oriented Programming (OOP) is a programming paradigm where the complete ...

Typology: Exercises

2022/2023

Uploaded on 03/01/2023

vernon
vernon 🇺🇸

4.8

(5)

216 documents

1 / 10

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1 | P a g e
Commonly asked
OOPS
Interview Questions
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Commonly asked OOPS Interview Questions and more Exercises Object Oriented Programming in PDF only on Docsity!

Commonly asked

OOPS

Interview Questions

Commonly Asked OOP Interview Questions

What is Object Oriented Programming? Object Oriented Programming (OOP) is a programming paradigm where the complete software operates as a bunch of objects talking to each other. An object is a collection of data and methods that operate on its data. Why OOP? The main advantage of OOP is better manageable code that covers following.

  1. The overall understanding of the software is increased as the distance between the language spoken by developers and that spoken by users.
  2. Object orientation eases maintenance by the use of encapsulation. One can easily change the underlying representation by keeping the methods same. OOP paradigm is mainly useful for relatively big software. See this for a complete example that shows advantages of OOP over procedural programing. What are main features of OOP? Encapsulation Polymorphism Inheritance What is encapsulation? Encapsulation is referred to one of the following two notions.
  3. Data hiding: A language feature to restrict access to members of an object. For example, private and protected members in C++.
  4. Bundling of data and methods together: Data and methods that operate on that data are bundled together.

What are the advantages of OOPS concepts? Major advantages of OOPS programming are; Simplicity: OOPS programming objects model real world objects, so the complexity is reduced and the program structure is clear. Modularity: Each object forms a separate entity whose internal workings are decoupled from other parts of the system. Modifiability: It is easy to make minor changes in the data representation or the procedures in an OO program. Changes inside a class do not affect any other part of a program, since the only public interface that the external world has to a class is through the use of methods. Extensibility: Adding new features or responding to changing operating environments can be solved by introducing a few new objects and modifying some existing ones. Maintainability: Objects can be maintained separately, making locating and fixing problems easier. Reusability: Objects can be reused in different programs. What is the difference between Procedural programming and OOPS? Procedural language is based on functions but object oriented language is based on real world objects. Procedural language gives importance on the sequence of function execution but object oriented language gives importance on states and behaviors of the objects. Procedural language exposes the data to the entire program but object oriented language encapsulates the data. Procedural language follows top down programming paradigm but object oriented language follows bottom up programming paradigm. Procedural language is complex in nature so it is difficult to modify, extend and maintain but object oriented language is less complex in nature so it is easier to modify, extend and maintain. Procedural language provides less scope of code reuse but object oriented language provides more scope of code reuse. What are the core concepts of OOPS? OOPS core concepts are; Abstraction Encapsulation

Polymorphism Inheritance Composition Association Aggregation What is Abstraction? Abstraction is an OOPS concept to construct the structure of the real world objects. During this construction only the general states and behaviors are taken and more specific states and behaviors are left aside for the implementers. What is Encapsulation? Encapsulation is an OOPS concept to create and define the permissions and restrictions of an object and its member variables and methods. A very simple example to explain the concept is to make the member variables of a class private and providing public getter and setter methods. Java provides four types of access level modifiers: public, protected, no modifier and private. What is the difference between Abstraction and Encapsulation? “Program to interfaces, not implementations” is the principle for Abstraction and “Encapsulate what varies” is the OO principle for Encapsulation. Abstraction provides a general structure of a class and leaves the details for the implementers. Encapsulation is to create and define the permissions and restrictions of an object and its member variables and methods. Abstraction is implemented in Java using interface and abstract class while Encapsulation is implemented using four types of access level modifiers: public, protected, no modifier and private. What is Polymorphism? Polymorphism is the occurrence of something in various forms. Java supports various forms of polymorphism like polymorphic reference variables, polymorphic method, polymorphic return types and polymorphic argument types.

When a class A has a member reference variable of type B then A “HAS-A” B. It is also known as Aggregation. What is Association? Association is a relationship between two objects with multiplicity. What is Aggregation? Aggregation is also known as “HAS-A” relationship. When class Car has a member reference variable of type Wheel then the relationship between the classes Car and Wheel is known as Aggregation. Aggregation can be understood as “whole to its parts” relationship. Car is the whole and Wheel is part. Wheel can exist without the Car. Aggregation is a weak association. What is Composition? Composition is a special form of Aggregation where the part cannot exist without the whole. Composition is a strong Association. Composition relationship is represented like aggregation with one difference that the diamond shape is filled. What is Dependency? When one class depends on another because it uses that at some point in time then this relationship is known as Dependency. One class depends on another if the independent class is a parameter variable or local variable of a method of the dependent class. A Dependency is drawn as a dotted line from the dependent class to the independent class with an open arrowhead pointing to the independent class. What is the difference between Association and Dependency? The main difference between Association and Dependency is in case of Association one class has an attribute or member variable of the other class type but in case of Dependency a method takes an argument of the other class type or a method has a local variable of the other class type.

What is a Class? A class is the specification or template of an object. What is an Object? Object is instance of class. Define a constructor? Constructor is a method used to initialize the state of an object, and it gets invoked at the time of object creation. Rules forconstructor are: Constructor Name should be same asclass name. Constructor must have no return type. Define Destructor? Destructor is a method which is automatically called when the object ismade ofscope or destroyed. Destructor name is also same asclass name but with the tilde symbol before the name. What is Inline function? Inline function is a technique used by the compilers and instructs to insert complete body of the function wherever that function is used in the program source code. What is operator overloading? Operator overloading is a function where different operators are applied and depends on the arguments. Operator,-,* can be used to pass through the function , and it has their own precedence to execute. What is an abstract class? An abstract class is a class which cannot be instantiated. Creation of an object is not possible with abstract class , but it can be inherited. An abstract class can contain only Abstract method. Java allows only abstract method in abstract class while for other language it allows non-abstract method as well.

What is the difference between structure and a class? Structure default access type is public , but class access type is private. A structure is used for grouping data whereas class can be used for grouping data and methods. Structures are exclusively used for data and it doesn’t require strict validation , but classes are used to encapsulates and inherit data which requires strict validation.