Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
31 views12 pages

Interview Questions Final

The document contains a comprehensive set of interview questions and answers related to Object-Oriented Programming (OOP), .NET Core, C# programming, MVC architecture, API development, JavaScript, and SQL. Key topics include principles of OOP, service lifetimes in ASP.NET Core, MVC components, API security, JavaScript data types, and SQL key constraints. It also includes code examples for C# functions and explanations of programming concepts.

Uploaded by

Manoj Manu
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)
31 views12 pages

Interview Questions Final

The document contains a comprehensive set of interview questions and answers related to Object-Oriented Programming (OOP), .NET Core, C# programming, MVC architecture, API development, JavaScript, and SQL. Key topics include principles of OOP, service lifetimes in ASP.NET Core, MVC components, API security, JavaScript data types, and SQL key constraints. It also includes code examples for C# functions and explanations of programming concepts.

Uploaded by

Manoj Manu
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/ 12

Interview Questions

OOPS
1. What is Object-Oriented Programming (OOP)?
Object-Oriented Programming is a programming paradigm based on the concept of
"objects," which can contain data in the form of fields (attributes or properties) and
code in the form of procedures (methods).
2. What are the main principles of OOP?
The four main principles of OOP are:
Encapsulation: Bundling the data (fields) and methods that operate on the data
into a single unit (class), and restricting access to some of the object's components.
Abstraction: Hiding complex implementation details and showing only the
necessary features of an object.
Inheritance: Allowing a new class to take on the properties and behaviors of an
existing class.
Polymorphism: Ability to define multiple behaviors for a method, allowing objects
to be treated as instances of their parent class.
3. What is the difference between a class and an object?
Class: A blueprint or prototype from which objects are created. It defines the
properties and behaviors that the objects created from the class will have.
Object: An instance of a class. It is created at runtime and represents a specific
entity with defined properties and methods.
4. Explain Encapsulation in C#. How is it implemented?
Encapsulation is the practice of hiding the internal state of an object and only
allowing controlled access through public methods.
In C#, encapsulation is implemented using access modifiers like private, public,
protected, etc., and by providing public getter and setter methods to access the
private fields.
5. What is Inheritance? How does it work in C#?
Inheritance allows one class to inherit fields and methods from another class. The
class that inherits is called a derived class, and the class it inherits from is called a
base class.
In C#, inheritance is implemented using the colon (:) symbol.
class Animal {
public void Eat() {
Console.WriteLine("Eating");
}
}
class Dog : Animal {
public void Bark() {
Console.WriteLine("Barking");
}
}
6. What is Polymorphism? Explain its types in C#.
Polymorphism allows objects of different types to be treated as objects of a common
base class.
There are two types of polymorphism in C#:
Compile-time (Static) Polymorphism: Achieved using method overloading or
operator overloading.
Runtime (Dynamic) Polymorphism: Achieved using method overriding with the
virtual and override keywords.
7. What is the difference between Abstraction and Encapsulation?
Abstraction focuses on hiding the complexity of the system by showing only the
necessary details, while Encapsulation deals with bundling data and restricting
access to it.
Abstraction is typically achieved through interfaces or abstract classes, while
Encapsulation is implemented with access modifiers.
8. What is an abstract class? How is it different from an interface?
Abstract Class: A class that cannot be instantiated and is meant to be subclassed.
It can have both abstract methods (without implementation) and non-abstract
methods (with implementation).
Interface: A contract that contains only method declarations (no implementation).
A class that implements an interface must provide implementations for all of the
interface's methods.
Key differences:
A class can inherit from only one abstract class, but it can implement multiple
interfaces.
An abstract class can have fields, constructors, and method implementations,
whereas an interface cannot.
9. What is method overloading?
Method overloading is the ability to define multiple methods in the same class with
the same name but different signatures (parameter types, number of parameters,
etc.).
Example:
public class Calculator {
public int Add(int a, int b) {
return a + b;
}
public double Add(double a, double b) {
return a + b;
}
}
10. What is method overriding?
Method overriding allows a subclass to provide a specific implementation of a
method that is already defined in its base class.
The method in the base class must be marked as virtual, and the derived class uses
the override keyword to modify it.
Example:
class Animal {
public virtual void MakeSound() {
Console.WriteLine("Some sound");
}
}
class Dog : Animal {
public override void MakeSound() {
Console.WriteLine("Bark");
}
}
11. Can you explain the concept of asynchronous programming in C# using
async and await?
Asynchronous programming allows you to run tasks without blocking the main
thread. By marking a method async, you can use the await keyword, which pauses
the method until an awaited task is complete. This is useful for I/O-bound operations
like database calls, ensuring responsiveness.

.Net Core
1.Different Service Lifetimes in ASP.NET Core.
2. What is dependency injection in .NET?
Dependency injection (DI) is a design pattern that allows for decoupling of the
objects and their dependencies. Instead of creating dependencies directly within
a class, you pass them in, often through the constructor. This makes your code
more testable and flexible. In .NET, DI is built-in via the
Microsoft.Extensions.DependencyInjection namespace.
Programs
1.C# Function to Remove Duplicates Without Built-in Functions:
public static int[] RemoveDuplicates(int[] arr)
{
// Array to store unique elements
List<int> uniqueElements = new List<int>();

// Iterate through the input array


for (int i = 0; i < arr.Length; i++)
{
bool isDuplicate = false;

// Check if the element already exists in the uniqueElements list


for (int j = 0; j < uniqueElements.Count; j++)
{
if (arr[i] == uniqueElements[j])
{
isDuplicate = true;
break;
}
}

// If the element is not a duplicate, add it to the list


if (!isDuplicate)
{
uniqueElements.Add(arr[i]);
}
}

// Convert the List to an array


return uniqueElements.ToArray();
}

// Test the function


int[] arr = { 1, 2, 3, 2, 4, 3 };
int[] result = RemoveDuplicates(arr);
Console.WriteLine(string.Join(", ", result)); // Output: 1, 2, 3, 4

2.C# Program to Reverse a String Without Using Built-in Functions:


public static string ReverseString(string input)
{
char[] charArray = new char[input.Length];
int index = 0;

// Iterate through the string in reverse order


for (int i = input.Length - 1; i >= 0; i--)
{
charArray[index] = input[i];
index++;
}

// Convert the char array back to a string


return new string(charArray);
}

// Test the function


string result = ReverseString("hello");
Console.WriteLine(result); // Output: "olleh"

MVC:
1.What is MVC, and what are the components?
MVC stands for Model-View-Controller, which is a design pattern used for separating
an application’s concerns:
 Model: Represents the data and business logic. It retrieves, stores, and
manipulates data from the database or other sources.
 View: The user interface that displays data from the model. It renders the
final output to the user.
 Controller: Handles user input and interactions. It processes user requests,
interacts with the model, and returns the response in the form of a view.
2.What is the difference between ViewData, ViewBag, and TempData in
MVC?
ViewData: A dictionary object used to pass data from the controller to the view. It
requires explicit casting and is available only during the current request.
ViewBag: A dynamic object that works like ViewData but allows simpler syntax
without explicit casting.
TempData: Used to pass data between controllers or between actions in the same
controller. Data is persisted only for a single request or until it is read.
3.Explain Action Filters in MVC.
Action Filters are attributes that allow you to add pre-processing and post-
processing logic to controller actions.
Common types of action filters:
 Authorization Filters: Control user authentication and authorization (e.g.,
[Authorize]).
 Action Filters: Run custom code before or after an action (e.g.,
[HandleError]).
 Result Filters: Run code before or after a view result is processed.
 Exception Filters: Handle errors or exceptions raised during action
execution.
4. What is the difference between PartialView and View in MVC?
PartialView: Renders only a portion of the view (a user control or part of a page). It
does not have a full layout and is often used for reusable UI components like menus
or sidebars.
View: Renders a full page, including the layout, headers, footers, and other UI
components.
API Development:
1.How do you secure APIs in .NET?
API security in .NET is typically done using JWT (JSON Web Tokens) for authentication
and authorization. You can also apply API keys, use HTTPS for secure
communication, and restrict access using roles or claims-based authorization.
2.Can you explain the difference between RESTful APIs and SOAP services?
RESTful APIs are lightweight, use HTTP methods (GET, POST, PUT, DELETE), and are
typically stateless, returning JSON or XML. SOAP is a protocol that relies on XML
messaging, has stricter standards (e.g., WSDL), and includes more built-in error
handling and security features.
3.What is Swagger?
Swagger is an open-source framework that helps developers design, build,
document, and consume RESTful APIs. It provides a set of tools to automatically
generate documentation for APIs, making it easier for developers to understand and
interact with them.

JavaScript:
1.What are the different data types in JavaScript?
JavaScript has the following data types:
Primitive types: string, number, boolean, undefined, null, symbol, and bigint.
Non-primitive type: object (includes arrays, functions, and objects).
2.What is the difference between == and === in JavaScript?
== is the loose equality operator, which compares values after performing type
coercion if needed. For example, 1 == '1' is true because 1 is coerced into a string.
=== is the strict equality operator, which compares both the value and the type.
For example, 1 === '1' is false because one is a number and the other is a string.
3.What is undefined vs null in JavaScript?
undefined means a variable has been declared but not assigned a value.
null is an assignment value that represents no value or an intentional empty object.
4.Explain the difference between let, var, and const.
var: Has function scope, can be re-declared and updated, and is hoisted.
let: Has block scope, can be updated but not re-declared in the same scope.
const: Has block scope, cannot be re-declared or updated (though objects and
arrays can be mutated).
5.What is hoisting in JavaScript?
Hoisting is JavaScript’s default behavior of moving declarations to the top of the
current scope before code execution. This applies to variables declared with var and
functions, but only their declarations are hoisted, not the initializations.

SQL:
1.Different Keys Constraints in SQL Server?
 Primary Key - A primary key is a column (or a set of columns) that uniquely
identifies each row in a table. It ensures that no two rows have the same
value for this column(s), and it does not allow NULL values.
 Foreign Key - A foreign key is a column (or set of columns) in one table that
references the primary key or unique key in another table. It is used to
establish and enforce a link between the data in two tables, ensuring
referential integrity.
 Unique Key - A unique key ensures that all the values in a column or a set of
columns are unique. Unlike the primary key, a table can have multiple unique
keys, and it allows NULL values (but only one NULL per column).
 Composite Key - A composite key is a key that consists of more than one
column to uniquely identify a row in the table. It can be used as either a
primary key or a unique key.
2. What is a Stored Procedure (SP)? Advantages of Stored Procedure?
A stored procedure is a precompiled set of one or more SQL statements that are
stored in a database. It can be called and executed as a single unit by the database
management system. Stored procedures are used to encapsulate repetitive tasks,
complex business logic, or operations that need to be performed on a database.
Benefits of Stored Procedures:
 Performance
 Security
 Maintainability
 Reduced Network Traffic
3. SP vs Function
4. Joins in SQL
Joins are used to combine data from two or more tables based on a related column
between them. Joins allow you to retrieve data from multiple tables in a single
query.
Types of Joins in SQL Server:
1. INNER JOIN
2. LEFT JOIN (LEFT OUTER JOIN)
3. RIGHT JOIN (RIGHT OUTER JOIN)
4. FULL JOIN (FULL OUTER JOIN)
5. CROSS JOIN
6. SELF JOIN
5. What is view in SQL?
A view in SQL is a virtual table that is created based on the result of a SELECT
query. It doesn’t store data itself but displays data from one or more underlying
tables.

6. CTE in SQL Server?


A Common Table Expression (CTE) in SQL Server is a temporary result set that
you can reference within a SELECT, INSERT, UPDATE, or DELETE query. It is defined
using the WITH keyword and typically makes complex queries easier to understand
and manage.
Syntax
WITH CTE_Name (Column1, Column2, ...)
AS
(
-- Your query goes here
SELECT Column1, Column2, ...
FROM Table
WHERE condition
)
-- You can use the CTE in the main query
SELECT *
FROM CTE_Name;

You might also like