Interview Questions
Object Oriented Programming 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 the methods which operate on that data.
The main advantage of OOP is better-managed code that covers the 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 the same.
3- The OOPs paradigm is mainly useful for relatively big software.
4- OOPs helps users to understand the software easily, although they don’t know the actual implementation.
5- With OOPs, the readability, understandability, and maintainability of the code increase multifold.
6- Even very big software can be easily written and managed easily using OOPs.
1. Imperative Programming Paradigm:
- Procedural Programming Paradigm
- Object-Oriented Programming
- Parallel Programming
2- Declarative Programming Paradigm:
- Logical Programming Paradigm
- Functional Programming Paradigm
- Database Programming Paradigm
The programming languages that use and follow the Object-Oriented Programming paradigm or OOPs, are known as Object-Oriented Programming languages. Some of the major Object-Oriented Programming languages include:
- C++
- C#
- Java
- Javascript
- Python
- PHP
And many more.
The main feature of the OOPs, also known as 4 pillars or basic principles of OOPs are as follows:
1- Encapsulation
2- Data Abstraction
3- Polymorphism
4- Inheritance
A class can be understood as a template or a blueprint, which contains some values, known as member data or member, and some set of rules, known as behaviors or functions. So when an object is created, it automatically takes the data and functions that are defined in the class.
Therefore the class is basically a template or blueprint for objects. Also one can create as many objects as they want based on a class.
For example, first, a car’s template is created. Then multiple units of cars are created based on that template.
An object refers to the instance of the class, which contains the instance of the members and behaviors defined in the class template. In the real world, an object is an actual entity to which a user interacts, whereas class is just the blueprint for that object. So the objects consume space and have some characteristic behavior.
For example, a specific car (bmw, ford, etc...).
The subclass is a part of Inheritance. The subclass is an entity, which inherits from another class. It is also known as the child class or delivered class.
Superclass is also a part of Inheritance. The superclass is an entity, which allows subclasses or child classes to inherit from itself.
It is also known as the parent class or base class.
The various types of inheritance include:
1- Single inheritance
2- Multiple inheritances
3- Multi-level inheritance
4- Hierarchical inheritance
5- Hybrid inheritance
An interface refers to a special type of class, which contains methods, but not their definition. Only the declaration of methods is allowed inside an interface. To use an interface, you cannot create objects. Instead, you need to implement that interface and define the methods for their implementation.
If one class shares the behavior and structure defined in another multiple class, it is called multiple inheritance.
Inheritance is relationship between two or more classes where derived class inherits properties of pre-existing (class).
The idea of inheritance is simple, a class is derived from another class and uses data and implementation of that other class. The class which is derived is called child or derived or subclass and the class from which the child class is derived is called parent or base or superclass.
The main purpose of Inheritance is to increase code reusability. It is also used to achieve Runtime Polymorphism.
Access specifiers are special types of keywords that are used to specify or control the accessibility of entities like classes, methods, and so on.
Private, Public, and Protected are examples of access specifiers or access modifiers, also known as visibility markers.
Yes. The limitations of inheritance are:
1- Increased execution effort and time.
2- Tight coupling of parent and child class.
3- Requires correct implementation.
4- Requires jumping between different classes.
1- It requires intensive testing
2- Not apt for minor problems
3- It requires good planning
4- It takes more time to solve problems
5- Problems need to be thought in term of objects
1- OOPs is very helpful in solving very complex level of problems.
2- Highly complex programs can be created, handled, and maintained easily using object-oriented programming.
3- OOPs, promote code reuse, thereby reducing redundancy.
4- OOPs also helps to hide the unnecessary details with the help of Data Abstraction.
5- OOPs, are based on a bottom-up approach, unlike the Structural programming paradigm, which uses a top-down approach.
6- Polymorphism offers a lot of flexibility in OOPs.
Encapsulation is the process of binding data members and methods of a program together to do a specific job, without revealing unnecessary details.
Encapsulation can also be defined in two different ways:
1) Data hiding: Encapsulation is the process of hiding unwanted information, such as restricting access to any member of an object.
2) Data binding: Encapsulation is the process of binding the data members and the methods together as a whole, as a class.
- Class is a blueprint that you can create an object from.
- Object is a member in the main application.
For Example:
(Car) is a class.
(BMW, Ford) are objects.
The base class is the root class- the most generalized class. At the same time,
The superclass is the immediate parent class from which the other class inherits.
Abstraction is similar to data encapsulation and is very important in OOP.
It means showing only the necessary information and hiding the other irrelevant information from the user.
Abstraction is implemented using classes and interfaces.
In general terms, an abstract class is a class that is intended to be used for inheritance.
An abstract class can consist of both abstract and non-abstract methods.
- It cannot be instantiated. (Cannot create object from)
- Made for other classes to inherit prop & methods from.
- can have methods & properties.
- can have abstract methods & non-abstract methods.
- abstract methods no body code. (only parameters or arguments)
1- Extends:
- Keyword used to make inherit from the parent class.
2- Final:
- Keyword used to stop inheritance from this class.
Polymorphism is composed of two words - “poly”, which means “many”, and “morph”, which means “shapes”.
Therefore, Polymorphism refers to something that has many shapes.
In OOP, Polymorphism refers to the process by which some code, data, method, or object behaves differently under different circumstances or contexts.
For Example:
(Shape) has a (Circle, Triangle, Square), This is called polymorphism from one thing.
There are two types of polymorphism:
1- Compile-time polymorphism (also known as static polymorphism) is achieved through function or operator overloading.
2- Runtime polymorphism (also known as dynamic polymorphism) is achieved through function overriding.
- Overloading deals with multiple methods in the same class with the same name but different signatures.
- Overriding deals with two methods, one in a parent class & one in a child class, that have the same signatures.
- Abstract:
1- Abstract class doesn’t support multiple inheritance (can extend only one abstract class)
2- Abstract contains constructors & data members.
3- An abstract class can have final, non-final, static and non-static variables.
4- A class that is abstract can have both abstract and non-abstract methods.
- Interface:
1- An interface supports multiple inheritance. (can implements more than one interface)
2- Interface doesn't contains constructors & data members.
3- The interface has only static and final variables.
4- An interface can only have abstract methods.
Constructor:
- A constructor is a special member function of a class that is automatically called when an object is created.
Destructor:
- A destructor is a special member function of a class that is automatically called when an object of the class goes out of scope or is deleted.
- DDL: Stands for (Data Definition Language),
It's a language to deal with database structure, like (Create, Drop, Alter)
- DML: stands for (Data Manipulation Language),
It's a language to deal with database information, like (Select, Insert, Update, Delete)
They are a set of syntax used in SQL that have a specific job, but they have a little different
- Function: Must return a value and accept parameters only, like ( max(), min(), rand(), upper(), lower() ).
- Stored Procedures: It's optional to return a value or accept parameters, like ( rename, change, help ).
There are several storage engines in MySQL, and the table types depend on which storage engine is used. The common storage engines are:
1- InnoDB (default in MySQL for transactional data)
2- MyISAM (older, non-transactional storage engine)
3- MEMORY (stores data in memory)
4- CSV (stores data in CSV files)
5- ARCHIVE (used for storing large amounts of data, read-only)
There are three types of relationships used in MySQL.
1- One-to-one:
- Elements with a one to one relationship can be included as columns in the table.
2- One-to-many:
- One to many or many to one relationships both are same. It will occur when one row in a table is related to multiple rows in different table.
3- Many-to-many:
- Many rows in a table are related to many rows in different table is called many to many relationship.
SIX triggers are available in MySQL table.
1- BEFORE INSERT
2- AFTER INSERT
3- BEFORE UPDATE
4- AFTER UPDATE
5- BEFORE DELETE
6- AFTER DELETE
1- Flexibility: MySQL runs on all operating systems
2- Power: MySQL focuses on performance
3- Enterprise-Level SQL Features: MySQL had for some time been lacking in advanced features such as subqueries, views, and stored procedures.
4- Full-Text Indexing and Searching
5- Query Caching: This helps enhance the speed of MySQL greatly
6- Replication: One MySQL server can be duplicated on another, providing numerous advantages
7- Configuration and Security
- MyISAM is a storage engine in MySQL known for its simplicity and speed, but lacks support for transactions and foreign keys.
- InnoDB, on the other hand, is a more robust storage engine that supports transactions, foreign keys, and row-level locking, making it suitable for mission-critical applications.
The JOIN statement in MySQL is used to retrieve data from multiple tables based on a related column between them.
Different types of joins include:
1- INNER JOIN (returns rows when there is a match in both tables),
2- LEFT JOIN (returns all rows from the left table and matching rows from the right table),
3- RIGHT JOIN (returns all rows from the right table and matching rows from the left table),
4- FULL JOIN (returns all rows when there is a match in either table).
MySQL query optimization involves various techniques such as indexing, using appropriate data types, minimizing the number of queries, optimizing table structure, avoiding unnecessary calculations, and utilizing query caching.
- INNER JOIN returns only the rows that have matching values in both tables based on the join condition specified,
- OUTER JOIN returns all rows from one or both tables, with unmatched rows filled with NULL values where the join condition is not met.
MVC stands for Model-View-Controller.
- Model represents the data and database interaction.
- View represents the user interface,
- Controller acts as an intermediary between the Model and View to process incoming requests, retrieve data from the Model, and return the appropriate View.
Dependency injection and class dependency management are made easier with the help of the Laravel Service Container.
It allows you to bind classes into the container, resolve dependencies automatically, and inject them into your classes when needed.
The process of confirming a user's identification through credentials, like a username and password, is called authentication.
Authorization, on the other hand, is the process of determining whether a user has the necessary permissions to perform a certain action or access a certain resource.
Laravel Facades provide a static interface to classes available in the application's service container.
They allow you to access these classes in a simple and expressive way without needing to instantiate them manually.
Laravel Events and Listeners provide a simple and convenient way to implement event-driven programming in your application. Events are triggered when certain actions occur, and listeners are responsible for handling those events and executing the necessary code in response.
Laravel Mix is a wrapper around Webpack, a popular JavaScript module bundler. It simplifies the process of compiling assets such as JavaScript, CSS, and images, and provides a clean and expressive API for defining asset compilation tasks
Laravel supports four database systems:
1- MySQL.
2- Postgres.
3- SQLite.
4- SQL Server.
Lumen is a lightweight framework for building web applications in PHP. It is built on top of Laravel and follows the same best practices that you have come to know in Laravel.
Lumen was designed to be used as an alternative to Laravel when you only need to build small applications and services.
1- Blade Templating
2- Routing
3- Eloquent ORM
4- Middleware
5- Artisan(Command-Line Interface)
6- Security
7- In-built Packages
8- Caching
9- Service Providers
10- Facades
11- Service Container
1- Offers a rich set of functionalities like Eloquent ORM, Template Engine, Artisan, Migration system for databases, etc
2- Libraries & Modular
3- It supports MVC Architecture
4- Unit Testing
5- Security
6- Website built in Laravel is more scalable and secure.
7- It includes namespaces and interfaces that help to organize all resources.
8- Provides a clean API.
You can register services, events, etc., using a service provider before booting the application.
They help inject Laravel services or your application services and dependencies.
The register method in the Service Provider class binds classes and services to Service Containers.
And the boot method runs after the program includes all the dependencies in the container.
Then you can create routes and view composers in the boot method.
S - Single Responsibility Principle (SRP): The single responsibility principle ensures that every class or module should be accountable and responsible for only one functionality. There should be one and only one reason for changing any class.
O - Open Closed Principle (OCP): Every class is open for extension but closed for modification. Here, we are allowed to extend the entities behaviour by not modifying anything in the existing source code.
L - Liskov Substitution Principle(LSP): LSP principle states that the objects can be replaced by the subtype instances without affecting the correctness of the program.
I - Interface Segregation Principle (ISP): The ISP principle states that we can use as many interfaces specific to the client’s requirements instead of creating only one general interface. Clients should not be forced to implement the functionalities that they do not require.
D - Dependency Inversion Principle: Here, the high-level modules should not be dependent on the lower level modules or concrete implementations. Instead, they should be dependent on the abstractions.