Object Oriented Programming
1. What is Object Oriented Programming?
Object-Oriented Programming (OOPs) is a type of programming that is based on objects rather than just functions and procedures. Individual objects are grouped into classes. OOPs implement real-world entities like inheritance, polymorphism, hiding, etc into programming. It also allows binding data and code together.
2. Why use OOPs? OR Advantages of 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
3. What are the main features/pillars of OOPs?
- Inheritance
- Encapsulation
- Polymorphism
- Data Abstraction
4. What are the different types of inheritance?
- Single inheritance
- Multiple inheritance
- Multilevel inheritance
- Hierarchical inheritance
- Hybrid inheritance
5. What is the difference between multiple and multilevel inheritance?
6. What is hierarchical inheritance?
Hierarchical inheritance refers to inheritance where one base class has more than one subclass. For example, the vehicle class can have 'car', 'bike', etc as its subclasses.
7. What are the limitations of inheritance?
- Increases the time and effort required to execute a program as it requires jumping back and forth between different classes
- The parent class and the child class get tightly coupled
- Any modifications to the program would require changes both in the parent as well as the child class
- Needs careful implementation else would lead to incorrect results
8. What is a superclass?
A superclass or base class is a class that acts as a parent to some other class or classes. For example, the Vehicle class is a superclass of class Car.
9. What is a subclass?
A class that inherits from another class is called the subclass. For example, the class Car is a subclass or a derived of Vehicle class.
10. What is polymorphism?
Polymorphism is a feature of OOPs that allows objects to take on many forms. For example, a shape can be a circle, square, or triangle. Polymorphism can be achieved through method overloading and method overriding.
Polymorphism refers to the ability to exist in multiple forms. Multiple definitions can be given to a single interface. For example, if you have a class named Vehicle, it can have a method named speed but you cannot define it because different vehicles have different speeds. This method will be defined in the subclasses with different definitions for different vehicles.
11. What is static polymorphism?
Static polymorphism (static binding) is a kind of polymorphism that occurs at compile time. An example of compile-time polymorphism is method overloading.
12. What is dynamic polymorphism?
Runtime polymorphism or dynamic polymorphism (dynamic binding) is a type of polymorphism which is resolved during runtime. An example of runtime polymorphism is method overriding.
13. What is function/method overloading?
Method overloading is a feature of OOPs which makes it possible to give the same name to more than one method within a class if the arguments passed differ.
14. What is function/method overriding?
Method overriding is a feature of OOPs by which the child class or the subclass can redefine methods present in the base class or parent class. Here, the method that is overridden has the same name as well as the signature meaning the arguments passed and the return type.
15. What is operator overloading?
Operator overloading refers to implementing operators using user-defined types based on the arguments passed along with it.
16. Differentiate between overloading and overriding.
17. What is Abstraction?
Abstraction is a feature of OOPs that allows you to hide the implementation details of an object and only show the essential information to the user. For example, when you drive a car, you don't need to know how the engine works, you just need to know how to use the steering wheel, accelerator, and brakes.
Data abstraction is a very important feature of OOPs that allows displaying only the important information and hiding the implementation details. For example, while riding a bike, you know that if you raise the accelerator, the speed will increase, but you don't know how it actually happens. This is data abstraction as the implementation details are hidden from the rider.
18. How to achieve data abstraction?
Data abstraction can be achieved through:
- Abstract class
- Abstract method
19. What is an abstract class?
An abstract class is a class that consists of abstract methods. These methods are basically declared but not defined. If these methods are to be used in some subclass, they need to be exclusively defined in the subclass.
20. Can you create an instance of an abstract class?
No. Instances of an abstract class cannot be created because it does not have a complete implementation. However, instances of subclass inheriting the abstract class can be created.
21. What is an interface?
It is a concept of OOPs that allows you to declare methods without defining them. Interfaces, unlike classes, are not blueprints because they do not contain detailed instructions or actions to be performed. Any class that implements an interface defines the methods of the interface.
22. What is Encapsulation?
Encapsulation is a feature of OOPs that allows you to bundle data and methods that operate on that data into a single unit. This helps to protect the data from being accessed or modified by unauthorized code. For example, a class can have private variables that can only be accessed by the methods of that class.
Encapsulation refers to binding the data and the code that works on that together in a single unit. For example, a class. Encapsulation also allows data-hiding as the data specified in one class is hidden from other classes.
23. Differentiate between data abstraction and encapsulation.
24. What is Cohesion?
Cohesion refers to the degree to which the elements inside a module belong together. It is a qualitative measure that indicates the focus of a module. High cohesion is desirable because it implies that the elements within the module are related and work together to perform a specific task.
25. What are virtual functions?
Virtual functions are functions that are present in the parent class and are overridden by the subclass. These functions are used to achieve runtime polymorphism.
26. What are pure virtual functions?
Pure virtual functions or abstract functions are functions that are only declared in the base class. This means that they do not contain any definition in the base class and need to be redefined in the subclass.
27. What is a constructor?
A constructor is a special type of method that has the same name as the class and is used to initialize objects of that class.
28. What is a destructor?
A destructor is a method that is automatically invoked when an object is destroyed. The destructor also recovers the heap space that was allocated to the destroyed object, closes the files and database connections of the object, etc.
29. Types of constructors
Types of constructors differ from language to language. However, all the possible constructors are:
- Default constructor
- Parameterized constructor
- Copy constructor
- Static constructor
- Private constructor
30. What is a copy constructor?
A copy constructor creates objects by copying variables from another object of the same class. The main aim of a copy constructor is to create a new object from an existing one.
31. 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.
32. What is exception handling?
Exception handling in Object-Oriented Programming is a very important concept that is used to manage errors. An exception handler allows errors to be thrown and caught and implements a centralized mechanism to resolve them.
33. What is the difference between an error and an exception?
34. 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.
35. What are the limitations of OOPs?
- Usually not suitable for small problems
- Requires intensive testing
- Takes more time to solve the problem
- Requires proper planning
- The programmer should think of solving a problem in terms of objects
36. What are 'access specifiers'?
Access specifiers or access modifiers are keywords that determine the accessibility of methods, classes, etc in OOPs. These access specifiers allow the implementation of encapsulation. The most common access specifiers are public, private and protected. However, there are a few more which are specific to the programming languages.
1. What are Linked Lists?
A linked list is a data structure that can store a collection of items. In other words, linked lists can be utilized to store several objects of the same type. Each unit or element of the list is referred to as a node. Each node has its own data and the address of the next node. It is like a chain. Linked Lists are used to create graphs and trees.
2. What type of memory allocation is referred to for Linked lists?
Dynamic memory allocation is referred for Linked lists.
3. What is traversal in linked lists?
Term Traversal is used to refer to the operation of processing each element in the list.
4. What is Node in the link list? And name the types of Linked Lists?
Together (data + link) is referred to as the Node.
Types of Linked Lists are:
- Singly Linked List
- Doubly Linked List
- Multiply Linked List
- Circular Linked List
5. What is a Singly Linked list?
Singly Linked lists are a type of data structure. In a singly linked list, each node in the list stores the contents of the node and a reference or pointer to the next node in the list. It does not store any reference or pointer to the previous node.
6. What is the difference between Linear Array and Linked List?
7. What are the applications of Linked Lists?
Applications of Linked Lists are:
- Linked lists are used to implement queues, stacks, graphs, etc.
- In Linked Lists you don't need to know the size in advance.
- Linked lists let you insert elements at the beginning and end of the list.
8. What is the difference between singly and doubly linked lists?
A doubly linked list nodes contain three fields:
- An integer value and
- Two links to other nodes
- one to point to the previous node and
- other to point to the next node.
Whereas a singly linked list contains points only to the next node.
9. What are the applications that use Linked lists?
Both queues and stacks are often implemented using linked lists. Other applications are list, binary tree, skip, unrolled linked list, hash table, etc.
10. What is the biggest advantage of linked lists?
The biggest benefit of linked lists is that you do not specify a fixed size for your list. The more elements you add to the chain, the bigger the chain gets.
1. What do you understand about 'Database'?
Database is an organized collection of related data where the data is stored and organized to serve some specific purpose.
2. Define DBMS.
DBMS stands for Database Management System. It is a collection of application programs which allow the user to organize, restore and retrieve information about data efficiently and as effectively as possible.
Some of the popular DBMS's are MySql, Oracle, Sybase, etc.
3. Enlist the advantages of DBMS.
- Data is stored in a structured way and hence redundancy is controlled.
- Validates the data entered and provides restrictions on unauthorized access to the database.
- Provides backup and recovery of the data when required.
- It provides multiple user interfaces.
4. What do you understand about Data Redundancy?
Duplication of data in the database is known as data redundancy. As a result of data redundancy, duplicated data is present at multiple locations, hence it leads to wastage of the storage space and the integrity of the database is destroyed.
5. What are the various types of relationships in Database? Define them.
- One-to-one: One table has a relationship with another table having a similar kind of column. Each primary key relates to only one or no record in the related table.
- One-to-many: One table has a relationship with another table that has primary and foreign key relations. The primary key table contains only one record that relates to none, one or many records in the related table.
- Many-to-many: Each record in both the tables can relate to many numbers of records in another table.
6. Explain Normalization and De-Normalization.
Normalization: Normalization is the process of removing redundant data from the database by splitting the table in a well-defined manner in order to maintain data integrity. This process saves much of the storage space.
De-normalization: De-normalization is the process of adding up redundant data on the table in order to speed up the complex queries and thus achieve better performance.
7. What are the different types of Normalization?
- First Normal Form (1NF): A relation is said to be in 1NF only when all the entities of the table contain unique or atomic values.
- Second Normal Form (2NF): A relation is said to be in 2NF only if it is in 1NF and all the non-key attributes of the table are fully dependent on the primary key.
- Third Normal Form (3NF): A relation is said to be in 3NF only if it is in 2NF and every non-key attribute of the table is not transitively dependent on the primary key.
8. What is SQL?
Structured Query language, SQL is an ANSI (American National Standard Institute) standard programming language that is designed specifically for storing and managing the data in the relational database management system (RDBMS) using all kinds of data operations.
9. How many SQL statements are used? Define them.
SQL statements are basically divided into three categories, DDL, DML, and DCL.
- Data Definition Language (DDL) commands are used to define the structure that holds the data. These commands are auto-committed i.e. changes done by the DDL commands on the database are saved permanently.
- Data Manipulation Language (DML) commands are used to manipulate the data of the database. These commands are not auto-committed and can be rolled back.
- Data Control Language (DCL) commands are used to control the visibility of the data in the database like revoke access permission for using data in the database.
10. Enlist the advantages of SQL.
- Simple SQL queries can be used to retrieve a large amount of data from the database very quickly and efficiently.
- SQL is easy to learn and almost every DBMS supports SQL.
- It is easier to manage the database using SQL as no large amount of coding is required.
11. Enlist some commands of DDL, DML, and DCL.
Data Definition Language (DDL) commands:
- CREATE to create a new table or database.
- ALTER for alteration.
- TRUNCATE to delete data from the table.
- DROP to drop a table.
- RENAME to rename a table.
Data Manipulation Language (DML) commands:
- INSERT to insert a new row.
- UPDATE to update an existing row.
- DELETE to delete a row.
- MERGE for merging two rows or two tables.
Data Control Language (DCL) commands:
- COMMIT to permanently save.
- ROLLBACK to undo the change.
- SAVEPOINT to save temporarily.
12. Explain the terms 'Record', 'Field' and 'Table' in terms of database.
Record: Record is a collection of values or fields of a specific entity. For Example, An employee, Salary account, etc.
Field: A field refers to an area within a record that is reserved for specific data. For Example, Employee ID.
Table: Table is the collection of records of specific types. For Example, the Employee table is a collection of records related to all the employees.
13. What are the advantages and disadvantages of views in the database?
View is a virtual table that does not have its data on its own rather the data is defined from one or more underlying base tables.
Advantages of Views:
- As there is no physical location where the data in the view is stored, it generates output without wasting resources.
- Data access is restricted as it does not allow commands like insertion, updation, and deletion.
Disadvantages of Views:
- The view becomes irrelevant if we drop a table related to that view.
- Much memory space is occupied when the view is created for large tables.
14. What do you understand about Functional dependency?
A relation is said to be in functional dependency when one attribute uniquely defines another attribute.
For Example, R is a Relation, X and Y are two attributes. T1 and T2 are two tuples. Then, T1[X]=T2[X] and T1[Y]=T2[Y]
Means, the value of component X uniquely defines the value of component Y.
Also, X->Y means Y is functionally dependent on X.
15. When is functional dependency said to be fully functional dependent?
To fulfill the criteria of fully functional dependency, the relation must meet the requirement of functional dependency.
A functional dependency 'A' and 'B' are said to be fully functional dependent when removal of any attribute say 'X' from 'A' means the dependency does not hold anymore.
16. What do you understand by the E-R model?
E-R model is an Entity-Relationship model which defines the conceptual view of the database. The E-R model basically shows the real-world entities and their association/relations. Entities here represent the set of attributes in the database.
17. Define Entity, Entity type, and Entity set.
Entity: Entity can be anything, be it a place, class or object which has an independent existence in the real world.
Entity Type: Entity Type represents a set of entities that have similar attributes.
Entity Set: Entity Set in the database represents a collection of entities having a particular entity type.
18. Define a Weak Entity set.
Weak Entity set is the one whose primary key comprises its partial key as well as the primary key of its parent entity. This is the case because the entity set may not have sufficient attributes to form a primary key.
19. Explain the terms 'Attribute' and 'Relations'
Attribute: Attribute is described as the properties or characteristics of an entity. For Example, Employee ID, Employee Name, Age, etc., can be attributes of the entity Employee.
Relation: Relation is a two-dimensional table containing a number of rows and columns where every row represents a record of the relation. Here, rows are also known as 'Tuples' and columns are known as 'Attributes'.
20. What is the Database transaction?
Sequence of operation performed which changes the consistent state of the database to another is known as the database transaction. After the completion of the transaction, either the successful completion is reflected in the system or the transaction fails and no change is reflected.
21. What do you understand by Join?
Join is the process of deriving the relationship between different tables by combining columns from one or more tables having common values in each. When a table joins with itself, it is known as Self Join.
22. What are the disadvantages of a Query?
- Indexes are not present.
- Stored procedures are excessively compiled.
- Difficulty in interfacing.
23. Define Join types with examples.
a) Inner JOIN: Inner JOIN is also known as a simple JOIN. This SQL query returns results from both the tables having a common value in rows.
SELECT * from employee, employee_info WHERE employee.EmpID = employee_info.EmpID;
b) Natural JOIN: This is a type of Inner JOIN that returns results from both the tables having the same data values in the columns of both the tables to be joined.
SELECT * from employee NATURAL JOIN employee_info;
c) Cross JOIN: Cross JOIN returns the result as all the records where each row from the first table is combined with each row of the second table.
SELECT * from employee CROSS JOIN employee_info;
d) Right JOIN: Right JOIN is also known as Right Outer JOIN. This returns all the rows as a result from the right table even if the JOIN condition does not match any records in the left table.
SELECT * from employee RIGHT OUTER JOIN employee_info on (employee.EmpID = employee_info.EmpID);
e) Left JOIN: Left JOIN is also known as Left Outer JOIN. This returns all the rows as a result of the left table even if the JOIN condition does not match any records in the right table.
SELECT * from employee LEFT OUTER JOIN employee_info on (employee.EmpID = employee_info.EmpID);
f) Outer/Full JOIN: Full JOIN return results in combining the result of both the Left JOIN and Right JOIN.
SELECT * from employee FULL OUTER JOIN employee_info on (employee.EmpID = employee_info.EmpID);
24. Explain the Data Dictionary.
Data dictionary is a set of information describing the content and structure of the tables and database objects. The job of the information stored in the data dictionary is to control, manipulate and access the relationship between database elements.
25. Explain the Primary Key and Composite Key.
Primary Key: Primary Key is that column of the table whose every row data is uniquely identified. Every row in the table must have a primary key and no two rows can have the same primary key. Primary key value can never be null nor can it be modified or updated.
Composite Key: Composite Key is a form of the candidate key where a set of columns will uniquely identify every row in the table.
26. What do you understand about the Unique key?
A Unique key is the same as the primary key whose every row data is uniquely identified with a difference of null value i.e. Unique key allows one value as a NULL value.
27. Name the different data models that are available for database systems.
Different data models are:
- Relational model
- Network model
- Hierarchical model
28. Differentiate between 'DELETE', 'TRUNCATE' and 'DROP' commands.
- After the execution of 'DELETE' operation, COMMIT and ROLLBACK statements can be performed to retrieve the lost data.
- After the execution of 'TRUNCATE' operation, COMMIT, and ROLLBACK statements cannot be performed to retrieve the lost data.
- 'DROP' command is used to drop the table or key like the primary key/foreign key
1. Reverse 2 or more consecutive odd numbers containing nodes in a linked list.
This is a coding problem that requires identifying consecutive odd numbers in a linked list and reversing them.
2. Find 2nd maximum using 1 loop(O(N)) in an array.
Find the second largest element in an array using a single loop with O(N) time complexity.
3. Find the largest window sum in an array.
This is a sliding window problem to find the maximum sum of a subarray of given size.
4. Find a reflection BST tree.
Determine if a Binary Search Tree is a reflection (mirror image) of another BST.
5. Find whether a linked list is circular or not.
Detect if a linked list forms a circle (the last node points back to any previous node).
6. Detect the cycle in a linked list.
Use Floyd's Cycle Detection Algorithm (Tortoise and Hare) to detect cycles in a linked list.
7. Find the first non repeated element in a string.
Find the first character in a string that appears only once.
8. Write recursive code for fibonacci series.
Implement the Fibonacci sequence using recursion.
9. How to traverse Bubble Sort and Selection Sort?
Explain the traversal mechanism and implementation of Bubble Sort and Selection Sort algorithms.
10. Write code for merge sort.
Implement the merge sort algorithm using divide and conquer approach.
11. Delete a node of linked list without knowing the head.
Delete a node from a linked list when you only have access to that node (not the head).
12. Delete the 5th node from a singly linked list (1->2->3->4->5) when head points to 4.
You are given a singly linked list e.g 1->2->3->4->5. Suppose that your head is pointing on 4. You have to delete the 5th Node. Note: You cannot move the pointer backwards.
13. Merge two unsorted arrays in sorted manner.
You have two unsorted arrays. You have to merge two arrays in the sorted manner. (Need Best Solution).
14. Check if the given string is palindrome or not?
Determine if a string reads the same forwards and backwards.
15. Find pair of numbers whose sum is equal to 5.
You are given an array. Find the pair of numbers whose sum is equal to 5.
16. Add a new node to the end of linked list with only head pointer.
You are given a linked list with a head pointer only. Your task is to add a new node to the linked list at the end. (Note: You have only one pointer pointing at head)
E.g 1->2->3->4->5
New node will be appended after 5.
1. Tell us something about yourself
Interviews usually start with the question "Tell us something about yourself". This is the very beginning of your interview where you have to be very precise about your answer because interviewers are expecting many things from you out of this question.
Your answer should reflect:
- Your Information
- Your past education
- Your FYP (optional)
- Your past industrial experience
- If you don't have any industrial experience then mention your FYP and self projects and learnings
2. Research the Company
Try to get to know about the company for which you are applying and before appearing in the interview. Get to know about them by visiting their website or LinkedIn profiles. This will help you to answer the question "What do you know about us?"
3. Why do you want to work here?
This is a common interview question that requires you to demonstrate your knowledge about the company and align your career goals with their mission and values.
4. Be confident
Confidence is the key to pass an interview. Show confidence in your abilities and answers.
5. Stick to the point
Try to avoid narrating stories rather than actual answers. Be concise and direct in your responses.
6. Be honest about what you don't know
Don't hesitate to tell interviews you don't know the answer. Just be formal saying "I am not sure about the answer for this question but I'll go through it later".
7. Ask questions at the end
Interviewers usually end the interview by asking you "Do you have any questions?". Try to show them your interest. Come up with questions and feel free to ask them.