0% found this document useful (0 votes)
2 views21 pages

Interview Questions

The document provides a comprehensive overview of Java and SQL, categorizing questions and answers into beginner, intermediate, and advanced levels. It covers fundamental concepts such as Java's object-oriented principles, data types, exception handling, and SQL commands, including joins and normalization. This resource serves as a preparation guide for interviews, particularly for roles at Accenture.

Uploaded by

Swayam Jilla
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views21 pages

Interview Questions

The document provides a comprehensive overview of Java and SQL, categorizing questions and answers into beginner, intermediate, and advanced levels. It covers fundamental concepts such as Java's object-oriented principles, data types, exception handling, and SQL commands, including joins and normalization. This resource serves as a preparation guide for interviews, particularly for roles at Accenture.

Uploaded by

Swayam Jilla
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Beginner Level

1. What is Java? Answer: Java is a high-level, object-oriented programming language that follows the principle of
"write once, run anywhere." It is platform-independent and widely used for building web, mobile, and desktop
applications.

2. What is the JDK, JRE, and JVM? Answer:

o JDK (Java Development Kit): A toolkit that includes the JRE and development tools (compiler,
debugger).

o JRE (Java Runtime Environment): Provides libraries and resources needed to run Java programs.

o JVM (Java Virtual Machine): Executes Java bytecode and provides platform independence.

3. What is bytecode in Java? Answer: Bytecode is the intermediate code generated by the Java compiler. It is
executed by the JVM and allows Java programs to be platform-independent.

4. Explain the concept of the ‘main’ method in Java. Answer: The main() method is the entry point for Java
programs. It has the signature public static void main(String[] args), where execution starts.

5. What are the data types in Java? Answer: Java has two types of data types:

o Primitive: byte, short, int, long, float, double, char, boolean

o Non-Primitive: String, Arrays, Classes, Objects

6. What is an object in Java? Answer: An object is an instance of a class. It contains fields (data) and methods
(behavior) to represent real-world entities.

7. What is inheritance in Java? Answer: Inheritance allows one class to inherit properties and methods from
another class using the extends keyword.

8. What is encapsulation? Answer: Encapsulation is a mechanism where the data (fields) of a class is hidden from
other classes and can only be accessed through methods (getters and setters).

9. What is polymorphism in Java? Answer: Polymorphism means "many forms." In Java, it refers to the ability of
a method to perform different tasks based on the object that it is acting upon. It can be achieved through
method overloading and method overriding.

10. What is the difference between method overloading and method overriding? Answer:

o Method Overloading: Same method name but different parameter lists within the same class.

o Method Overriding: Subclass provides a specific implementation for a method declared in the
superclass.

11. What is the difference between abstract classes and interfaces? Answer:

o Abstract Class: Can have abstract and non-abstract methods, supports constructor, can have instance
variables.

o Interface: Can only have abstract methods (Java 8 and above allow default methods), supports
multiple inheritance.

12. What is the use of the final keyword in Java? Answer: The final keyword is used to declare constants, prevent
method overriding, and prevent inheritance of classes.

13. What is a constructor in Java? Answer: A constructor is a special method that is called when an object is
created. It initializes the object and has the same name as the class.

14. Can a constructor be overridden? Answer: No, constructors cannot be overridden because they are not
inherited by subclasses.
15. What is a static method? Answer: A static method belongs to the class rather than the object. It can be called
without creating an instance of the class.

16. What is the this keyword? Answer: The this keyword refers to the current object of a class.

17. What is the super keyword in Java? Answer: The super keyword is used to refer to the parent class's methods
and constructors.

18. What is an exception in Java? Answer: An exception is an unwanted event that occurs during the execution of
a program, disrupting its flow. Java uses try-catch blocks for exception handling.

19. What is the difference between checked and unchecked exceptions? Answer:

o Checked Exceptions: Checked at compile-time (e.g., IOException).

o Unchecked Exceptions: Checked at runtime (e.g., NullPointerException).

20. What is a try-catch block in Java? Answer: A try-catch block is used to handle exceptions. Code that may throw
an exception is placed inside the try block, and the catch block handles the exception.

21. What is the purpose of the finally block? Answer: The finally block is executed after the try-catch block,
whether an exception is thrown or not, and is used for resource cleanup.

22. What is the difference between == and equals() in Java? Answer:

o == compares object references (memory addresses).

o equals() compares the actual content of objects.

23. What are wrapper classes in Java? Answer: Wrapper classes provide a way to use primitive data types as
objects. Example: Integer, Boolean, Double.

24. What is autoboxing and unboxing in Java? Answer: Autoboxing is the automatic conversion of primitives to
their corresponding wrapper classes, and unboxing is the reverse.

25. What is the String class in Java? Answer: The String class represents a sequence of characters. Strings are
immutable in Java, meaning their values cannot be changed once created.

Intermediate Level

26. What is a thread in Java? Answer: A thread is a lightweight process in Java. It allows multiple tasks to run
concurrently. Java supports multithreading with the Thread class or Runnable interface.

27. What is synchronization in Java? Answer: Synchronization is the mechanism that ensures that only one thread
can access a shared resource at a time to avoid inconsistencies.

28. What is a volatile keyword in Java? Answer: The volatile keyword is used for variables that may be changed
by different threads, ensuring that the value is read from and written to the main memory.

29. What is the difference between wait() and sleep() methods in Java? Answer:

o wait(): Releases the lock and waits for another thread to notify.

o sleep(): Puts the thread to sleep for a specified time but holds the lock.

30. What is a deadlock in Java? Answer: A deadlock occurs when two or more threads are waiting for each other
to release resources, causing both threads to remain blocked forever.

31. What is the difference between ArrayList and LinkedList in Java? Answer:
o ArrayList: Provides fast access to elements but slow insertion and deletion.

o LinkedList: Provides fast insertion and deletion but slower access to elements.

32. What is the Collections Framework in Java? Answer: The Collections Framework is a unified architecture for
managing and manipulating collections (e.g., List, Set, Map).

33. What is the difference between HashMap and TreeMap in Java? Answer:

o HashMap: Stores key-value pairs without order and allows null keys.

o TreeMap: Stores key-value pairs in a sorted order (based on natural ordering or comparator).

34. What is the Comparable interface in Java? Answer: The Comparable interface is used to define the natural
ordering of objects by implementing the compareTo() method.

35. What is the Comparator interface in Java? Answer: The Comparator interface provides a way to sort objects
in a custom order by overriding the compare() method.

36. What is garbage collection in Java? Answer: Garbage collection is the process by which the JVM automatically
removes objects that are no longer in use to free up memory.

37. What is the difference between StringBuilder and StringBuffer? Answer:

o StringBuilder: Non-synchronized, faster, used in single-threaded environments.

o StringBuffer: Synchronized, slower, used in multi-threaded environments.

38. What is the Java Stream API? Answer: The Java Stream API, introduced in Java 8, is used to process collections
of objects in a functional style. It supports operations like filtering, mapping, and reducing.

39. What is lambda expression in Java? Answer: Lambda expressions, introduced in Java 8, provide a concise way
to express functional interfaces using a syntax of parameters -> expression.

40. What are default methods in interfaces in Java? Answer: Default methods in interfaces, introduced in Java 8,
allow interfaces to have method implementations. They help in adding new methods to existing interfaces
without breaking the implementing classes.

Advanced Level

41. What is Java Reflection API? Answer: The Reflection API in Java allows the inspection and modification of
classes, methods, and fields at runtime. It is used for creating flexible and dynamic applications.

42. What is the difference between final, finally, and finalize() in Java? Answer:

o final: Keyword used to declare constants or prevent inheritance/overriding.

o finally: Block used to execute code regardless of whether an exception occurs or not.

o finalize(): Method used by garbage collector before destroying an object.

43. What is the Singleton design pattern in Java? Answer: The Singleton pattern ensures that only one instance
of a class is created and provides a global point of access to it.

44. What is the Factory design pattern in Java? Answer: The Factory pattern provides an interface for creating
objects but allows subclasses to alter the type of objects that will be created.

45. What is Dependency Injection in Java? Answer: Dependency Injection (DI) is a design pattern where an
object's dependencies are injected rather than the object managing them itself. It is often used in frameworks
like Spring.

46. What is the use of the transient keyword in Java? Answer: The transient keyword is used in serialization to
indicate that a field should not be serialized.
47. What is the Java Memory Model (JMM)? Answer: The Java Memory Model defines how threads interact
through memory and provides consistency guarantees. It ensures visibility of changes made by one thread to
other threads.

48. What is a Soft Reference in Java? Answer: Soft references are used for memory-sensitive caches, where the
garbage collector can reclaim the referenced object when memory is low.

49. What is the difference between PhantomReference and WeakReference in Java? Answer:

o WeakReference: The object is collected when no strong references exist.

o PhantomReference: The object is collected, but the reference is kept for cleanup before finalization.

50. What are microservices in Java? Answer: Microservices is an architectural style where an application is divided
into small, loosely coupled services that can be developed, deployed, and scaled independently. Java
frameworks like Spring Boot are commonly used for microservices.

Here are 50 SQL questions and answers, categorized from beginner to advanced levels, to help you prepare for your
Accenture interview:

Beginner Level

1. What is SQL? Answer: SQL (Structured Query Language) is a standard programming language used to manage
and manipulate relational databases. It is used to perform tasks such as querying data, updating records, and
managing database structures.

2. What are the different types of SQL commands? Answer: SQL commands are categorized into:

o DDL (Data Definition Language): CREATE, ALTER, DROP

o DML (Data Manipulation Language): SELECT, INSERT, UPDATE, DELETE

o DCL (Data Control Language): GRANT, REVOKE

o TCL (Transaction Control Language): COMMIT, ROLLBACK, SAVEPOINT

3. What is a primary key in SQL? Answer: A primary key is a column (or set of columns) that uniquely identifies
each record in a table. It ensures that no duplicate or NULL values exist.

4. What is a foreign key in SQL? Answer: A foreign key is a column or group of columns that creates a relationship
between two tables. It references the primary key of another table, enforcing referential integrity.

5. What is the difference between WHERE and HAVING clause? Answer:

o WHERE: Filters records before any grouping is applied.

o HAVING: Filters records after groups are created, typically used with GROUP BY.

6. What is the difference between DELETE and TRUNCATE? Answer:

o DELETE: Removes specific records based on a condition and can be rolled back.

o TRUNCATE: Removes all rows from a table and is faster but cannot be rolled back.

7. What is a JOIN in SQL, and what are its types? Answer: A JOIN is used to combine rows from two or more
tables based on a related column. Types include:

o INNER JOIN: Returns matching records from both tables.

o LEFT JOIN: Returns all records from the left table and matched records from the right table.

o RIGHT JOIN: Returns all records from the right table and matched records from the left table.
o FULL OUTER JOIN: Returns all records when there is a match in either table.

8. What is normalization? Answer: Normalization is the process of organizing database tables to reduce
redundancy and dependency. It involves dividing large tables into smaller ones and defining relationships
among them.

9. What is a NULL value in SQL? Answer: A NULL value in SQL represents missing or unknown data. It is not
equivalent to zero or an empty string.

10. What is the difference between UNION and UNION ALL? Answer:

o UNION: Combines the results of two queries and removes duplicate rows.

o UNION ALL: Combines the results of two queries without removing duplicates.

11. What is an INDEX in SQL, and why is it used? Answer: An index is a database object used to speed up the
retrieval of rows by creating a lookup table for faster access to records. However, it can slow down write
operations like INSERT and UPDATE.

12. What is a VIEW in SQL? Answer: A view is a virtual table based on the result set of a SQL query. It allows you
to store complex queries for reuse.

13. What is the difference between CHAR and VARCHAR in SQL? Answer:

o CHAR: Fixed-length string.

o VARCHAR: Variable-length string, which saves space by using only as much space as required for the
data.

14. What is the DISTINCT keyword in SQL? Answer: The DISTINCT keyword is used to return only unique values
from a query, eliminating duplicate records.

15. What is the LIMIT clause in SQL? Answer: The LIMIT clause is used to specify the maximum number of records
to return in a result set.

16. What is a subquery in SQL? Answer: A subquery is a query within another query. It is used to retrieve data
that will be used in the main query.

17. What is a SELF JOIN? Answer: A SELF JOIN is a regular join but with the same table. It is used to compare rows
within the same table.

18. What is a stored procedure in SQL? Answer: A stored procedure is a precompiled collection of SQL statements
stored in the database and executed as a unit to perform specific tasks.

19. What is a trigger in SQL? Answer: A trigger is a set of actions that are automatically executed when a specific
event (like INSERT, UPDATE, DELETE) occurs in a table.

20. What is a transaction in SQL? Answer: A transaction is a sequence of SQL operations executed as a single unit
of work. It ensures that either all operations are executed or none (atomicity).

Intermediate Level

21. What is the CASE statement in SQL? Answer: The CASE statement is used to perform conditional logic in SQL
queries, similar to if-else statements in programming.

22. What is a correlated subquery in SQL? Answer: A correlated subquery is a subquery that references columns
from the outer query. It is executed once for every row selected by the outer query.

23. How do you update multiple rows in SQL? Answer: You can update multiple rows by using the UPDATE
statement with a condition in the WHERE clause. For example:

sql
Copy code

UPDATE employees

SET salary = salary * 1.1

WHERE department_id = 10;

24. What is referential integrity in SQL? Answer: Referential integrity ensures that relationships between tables
remain consistent, meaning foreign keys must match the primary key in the referenced table or be NULL.

25. What is the GROUP BY clause used for? Answer: The GROUP BY clause groups rows that have the same values
in specified columns. It is commonly used with aggregate functions like COUNT, SUM, AVG, etc.

26. How do you delete duplicate records in a table? Answer:

sql

Copy code

DELETE FROM employees

WHERE id NOT IN (

SELECT MIN(id)

FROM employees

GROUP BY name, email

);

27. What is an aggregate function in SQL? Answer: Aggregate functions perform calculations on a set of values
and return a single value. Examples include COUNT(), SUM(), AVG(), MIN(), and MAX().

28. How do you fetch the top N records in SQL? Answer: In MySQL:

sql

Copy code

SELECT * FROM employees ORDER BY salary DESC LIMIT 5;

In SQL Server:

sql

Copy code

SELECT TOP 5 * FROM employees ORDER BY salary DESC;

29. What is the difference between RANK() and DENSE_RANK()? Answer:

o RANK(): Provides gaps in ranking if there are ties.

o DENSE_RANK(): Assigns consecutive ranks without gaps even if there are ties.

30. What is the EXISTS clause in SQL? Answer: The EXISTS clause is used to check for the existence of any record
in a subquery. It returns TRUE if the subquery returns any rows.

31. How do you perform a FULL OUTER JOIN? Answer:

sql

Copy code

SELECT * FROM employees


FULL OUTER JOIN departments

ON employees.department_id = departments.department_id;

32. How do you remove a column from an existing table? Answer:

sql

Copy code

ALTER TABLE employees DROP COLUMN email;

33. What is a composite key? Answer: A composite key is a combination of two or more columns used to uniquely
identify rows in a table.

34. How do you check if a table exists in SQL? Answer:

sql

Copy code

SELECT table_name

FROM information_schema.tables

WHERE table_name = 'employees';

35. What is COALESCE() function in SQL? Answer: The COALESCE() function returns the first non-NULL value from
a list of expressions.

36. How do you fetch the nth highest salary from a table? Answer:

sql

Copy code

SELECT salary

FROM employees e1

WHERE N-1 = (SELECT COUNT(DISTINCT salary) FROM employees e2 WHERE [Link] > [Link]);

37. What is a cross join? Answer: A cross join returns the Cartesian product of two tables, meaning every row in
the first table is paired with every row in the second table.

38. What is a recursive query in SQL? Answer: A recursive query is a query that refers to itself. It is commonly
used to traverse hierarchical data. Example:

sql

Copy code

WITH RECURSIVE hierarchy AS (

SELECT id, name, manager_id

FROM employees

WHERE manager_id IS NULL

UNION ALL

SELECT [Link], [Link], e.manager_id

FROM employees e

INNER JOIN hierarchy h ON e.manager_id = [Link]


)

SELECT * FROM hierarchy;

A recursive query is useful for navigating hierarchical data like organizational charts.

Advanced Level

39. What is a window function in SQL? Answer: A window function performs a calculation across a set of rows
related to the current row, without collapsing them into a single result. Example functions include
ROW_NUMBER(), RANK(), and LEAD().

40. What is partitioning in SQL? Answer: Partitioning is the process of dividing a large table into smaller, more
manageable pieces. It can be done by range, list, or hash partitioning to improve performance.

41. What is the MERGE statement in SQL? Answer: The MERGE statement allows you to perform INSERT, UPDATE,
and DELETE operations in a single statement based on a condition. It is useful for synchronizing tables.

sql

Copy code

MERGE INTO target_table t

USING source_table s

ON [Link] = [Link]

WHEN MATCHED THEN

UPDATE SET [Link] = [Link]

WHEN NOT MATCHED THEN

INSERT (id, name) VALUES ([Link], [Link]);

42. What is database sharding? Answer: Database sharding is a form of database partitioning where large datasets
are split across multiple databases to improve scalability and performance.

43. How do you optimize SQL queries? Answer: SQL queries can be optimized using techniques like:

o Adding appropriate indexes.

o Avoiding SELECT * and selecting only required columns.

o Using joins efficiently.

o Avoiding correlated subqueries when possible.

o Writing efficient WHERE clauses using indexed columns.

44. What is the WITH clause in SQL? Answer: The WITH clause allows you to define temporary result sets that can
be referenced within the main query, commonly used for complex subqueries.

sql

Copy code

WITH department_totals AS (

SELECT department_id, COUNT(*) AS employee_count

FROM employees

GROUP BY department_id
)

SELECT * FROM department_totals;

45. What is a materialized view? Answer: A materialized view stores the result of a query physically, allowing
faster query execution. Unlike a regular view, it needs to be refreshed to update the data.

46. How do you handle deadlocks in SQL? Answer: Deadlocks can be handled by:

o Optimizing transactions to lock fewer rows.

o Keeping transactions short.

o Using the SET DEADLOCK_PRIORITY to specify the priority of a session in the event of a deadlock.

47. What is ACID in SQL? Answer: ACID stands for Atomicity, Consistency, Isolation, and Durability, which are
properties of a transaction ensuring reliable processing of database operations.

48. What is database replication? Answer: Database replication is the process of copying data from one database
server to another to ensure consistency, improve reliability, and provide data redundancy.

49. What are Common Table Expressions (CTEs)? Answer: CTEs, defined with the WITH clause, allow the
temporary result of a query to be reused in subsequent queries within the same statement.

50. What is the difference between NVL() and COALESCE() in SQL? Answer:

o NVL(): Replaces NULL with a specified value, but is specific to Oracle.

o COALESCE(): Returns the first non-NULL value in a list and works across multiple SQL databases.

Here are 50 Python interview questions and answers, organized from beginner to advanced levels, to help you prepare
for your Accenture interview:

Beginner Level

1. What is Python? Answer: Python is an interpreted, high-level, general-purpose programming language known
for its simplicity, readability, and versatility. It supports multiple programming paradigms, including procedural,
object-oriented, and functional programming.

2. What are Python's key features? Answer:

o Interpreted

o Dynamically-typed

o High-level language

o Supports multiple paradigms

o Extensive standard library

o Community support

o Cross-platform

3. What is PEP 8? Answer: PEP 8 is the Python Enhancement Proposal that provides guidelines and best practices
for writing clean, readable, and consistent Python code.

4. How do you define a function in Python? Answer: Functions in Python are defined using the def keyword:

python
Copy code

def function_name(parameters):

return result

5. What are lists and tuples in Python? Answer:

o List: A mutable, ordered collection of elements.

o Tuple: An immutable, ordered collection of elements.

6. What is the difference between append() and extend() methods? Answer:

o append(): Adds an element to the end of a list.

o extend(): Adds elements of another list to the existing list.

7. How do you create a dictionary in Python? Answer: A dictionary is created using curly braces {} with key-value
pairs:

python

Copy code

my_dict = {'name': 'Alice', 'age': 25}

8. What is a set in Python? Answer: A set is an unordered collection of unique elements defined using curly
braces {}.

9. How do you iterate over a list in Python? Answer:

python

Copy code

for item in my_list:

print(item)

10. What is the difference between break and continue in loops? Answer:

o break: Exits the loop entirely.

o continue: Skips the current iteration and continues with the next one.

11. What is a lambda function in Python? Answer: A lambda function is an anonymous function defined using the
lambda keyword:

python

Copy code

add = lambda x, y: x + y

12. How do you handle exceptions in Python? Answer: Exception handling is done using try, except, else, and
finally blocks:

python

Copy code

try:

# Code that may raise an exception

except Exception as e:
# Handle exception

finally:

# Code that runs regardless of exceptions

13. What is the difference between is and == in Python? Answer:

o is: Checks if two variables point to the same object in memory.

o ==: Checks if two variables have the same value.

14. What is __init__ in Python? Answer: __init__ is a special method in Python classes, called a constructor. It
initializes object attributes.

15. What are Python decorators? Answer: Decorators are functions that modify the behavior of other functions
or methods. They are defined with the @decorator_name syntax.

16. How do you install external packages in Python? Answer: External packages can be installed using the pip
package manager:

bash

Copy code

pip install package_name

17. What is the with statement in Python? Answer: The with statement is used for managing resources like file
streams. It ensures resources are properly closed after use.

python

Copy code

with open('[Link]', 'r') as f:

data = [Link]()

18. What are list comprehensions in Python? Answer: List comprehensions provide a concise way to create lists:

python

Copy code

squares = [x**2 for x in range(10)]

19. What is the purpose of self in Python classes? Answer: self refers to the instance of the class and is used to
access its attributes and methods.

20. What is a generator in Python? Answer: A generator is a function that returns an iterator and yields values
one at a time using the yield keyword.

Intermediate Level

21. What is the difference between a shallow copy and a deep copy in Python? Answer:

o Shallow copy: Copies the reference pointers to the original objects, not the objects themselves
([Link]()).

o Deep copy: Copies both the reference pointers and the objects ([Link]()).

22. What is the map() function in Python? Answer: The map() function applies a given function to each item in
an iterable:

python
Copy code

result = map(lambda x: x**2, [1, 2, 3])

23. What are *args and **kwargs in Python? Answer:

o *args: Allows a function to accept any number of positional arguments.

o **kwargs: Allows a function to accept any number of keyword arguments.

24. What is the Global Interpreter Lock (GIL) in Python? Answer: The GIL is a mutex that protects access to Python
objects and prevents multiple threads from executing Python bytecodes simultaneously, which can be a
limitation for multi-threading.

25. How do you perform file handling in Python? Answer: File handling is done using the built-in open() function:

python

Copy code

f = open('[Link]', 'r')

content = [Link]()

[Link]()

26. What is __str__() and __repr__() in Python? Answer:

o __str__(): Provides a readable string representation of an object.

o __repr__(): Provides an unambiguous string representation of an object used for debugging.

27. How do you check if a file exists in Python? Answer: Using the os module:

python

Copy code

import os

if [Link]('[Link]'):

print("File exists")

28. What are modules and packages in Python? Answer:

o Module: A Python file containing code, functions, and variables.

o Package: A directory that contains multiple Python modules, with an __init__.py file to initialize the
package.

29. What is the filter() function in Python? Answer: The filter() function filters elements of an iterable based on a
condition:

python

Copy code

result = filter(lambda x: x % 2 == 0, [1, 2, 3, 4])

30. What is a closure in Python? Answer: A closure is a function that remembers the values from its enclosing
scope, even if the scope is no longer active.

31. What are try, except, else, and finally blocks in Python? Answer: They are used for exception handling in
Python. else is executed if no exception occurs, and finally is always executed regardless of exceptions.
32. How do you implement inheritance in Python? Answer:

python

Copy code

class Parent:

def parent_method(self):

print("Parent method")

class Child(Parent):

def child_method(self):

print("Child method")

33. What is multithreading in Python? Answer: Multithreading is the ability of a CPU to provide multiple threads
of execution concurrently, supported by the threading module in Python.

34. What is a context manager in Python? Answer: A context manager is used to manage resources using the with
statement. It ensures proper resource acquisition and release.

35. What is memoization in Python? Answer: Memoization is a technique for optimizing recursive functions by
caching previously computed results to avoid repeated calculations.

36. What is the difference between a class method and a static method in Python? Answer:

o Class method: Uses the @classmethod decorator and has access to the class via the cls parameter.

o Static method: Uses the @staticmethod decorator and does not have access to the class or instance.

37. How do you reverse a string in Python? Answer:

python

Copy code

reversed_string = my_string[::-1]

38. What is a mixin in Python? Answer: A mixin is a class that provides methods to other classes through multiple
inheritance, without being a standalone class itself.

39. What is duck typing in Python? Answer: Duck typing is a programming concept where the type or class of an
object is less important than the methods or properties it defines. In Python, "If it looks like a duck and quacks
like a duck, it's a duck."

40. What is the random module in Python? Answer: The random module is used to generate random numbers or
select random elements from sequences.

Advanced Level

41. What is metaprogramming in Python? Answer: Metaprogramming refers to the ability to treat code as data.
In Python, this can be achieved through decorators, metaclasses, and manipulating class definitions.

42. What is a metaclass in Python? Answer: A metaclass is a class of a class, meaning it defines the behavior of a
class. Classes are instances of metaclasses.

43. How do you perform benchmarking in Python? Answer: You can use the time or timeit module to benchmark
code execution time:

python
Copy code

import time

start = [Link]()

# Code to benchmark

end = [Link]()

print("Execution time:", end - start)

44. What are generators, and why are they useful? Answer: Generators yield items one at a time and are more
memory-efficient than lists because they don't store the entire collection in memory.

45. What is monkey patching in Python? Answer: Monkey patching refers to the practice of dynamically modifying
a class or module at runtime.

46. How does the Global Interpreter Lock (GIL) affect Python multithreading? Answer: The GIL ensures only one
thread executes Python bytecode at a time, which can limit the performance of CPU-bound programs in multi-
threaded contexts.

47. What is the difference between multiprocessing and multithreading in Python? Answer: Multithreading uses
threads (lightweight), while multiprocessing uses processes (heavier) with separate memory spaces.
Multiprocessing is better for CPU-bound tasks due to the GIL.

48. What is serialization in Python? Answer: Serialization is the process of converting an object into a format that
can be easily stored or transmitted, and then reconstructed later. In Python, this is done using pickle, json, etc.

49. What is the functools module used for? Answer: The functools module provides higher-order functions like
reduce(), lru_cache(), and partial() that work on or return functions.

50. What is the inspect module in Python? Answer: The inspect module provides functions to retrieve information
about live objects, such as modules, classes, and functions. It’s useful for debugging and introspection.
Angular

Beginner Level

1. What is Angular? Answer: Angular is a platform and framework for building single-page client applications
using HTML and TypeScript. It is developed and maintained by Google.

2. What are components in Angular? Answer: Components are the building blocks of Angular applications. Each
component consists of an HTML template, a CSS stylesheet, and a TypeScript class.

3. What is a module in Angular? Answer: An Angular module is a mechanism to group related components,
directives, pipes, and services. It helps organize an application into cohesive blocks of functionality.

4. What is data binding in Angular? Answer: Data binding is the mechanism of synchronizing data between the
model (component) and the view (template). It can be one-way or two-way binding.

5. What is dependency injection in Angular? Answer: Dependency Injection (DI) is a design pattern used to
implement IoC (Inversion of Control), allowing Angular to manage the dependencies of components and
services.

6. What are Angular directives? Answer: Directives are special markers in Angular that tell the compiler to do
something with the DOM. They can be structural (*ngIf, *ngFor) or attribute directives.

7. What is the difference between ngOnInit() and constructor in Angular? Answer:

o constructor: Used for dependency injection and initializing class members.

o ngOnInit(): Lifecycle hook called after Angular has initialized all data-bound properties.

8. What is Angular CLI? Answer: Angular CLI (Command Line Interface) is a tool that helps automate the
development workflow, including creating components, services, and running build processes.

9. How do you create a new Angular project? Answer: You can create a new Angular project using the Angular
CLI command:

bash

Copy code

ng new my-project

10. What is a service in Angular? Answer: A service is a class used to encapsulate business logic and data
manipulation that can be shared across multiple components.

11. What are Angular pipes? Answer: Pipes are used to transform data in templates. They can format data or
perform operations on data before displaying it (e.g., date, currency, uppercase).

12. What is routing in Angular? Answer: Routing is the mechanism that allows navigation between different views
or pages in an Angular application. It is configured using the Angular Router.

13. What is the purpose of ngFor directive? Answer: ngFor is a structural directive that iterates over a collection
and generates a template for each item in the collection.

14. How do you handle forms in Angular? Answer: Angular provides two ways to handle forms: Template-driven
forms and Reactive forms. Template-driven forms are simpler and suitable for basic forms, while Reactive forms
offer more control and flexibility.

15. What is Angular's change detection mechanism? Answer: Change detection is a process where Angular checks
for changes in the application state and updates the view accordingly. It uses a mechanism called Zones to
detect changes.

16. What is Angular's router outlet? Answer: RouterOutlet is a directive that acts as a placeholder where the
routed component will be displayed.
17. What is the role of @Injectable() decorator in Angular? Answer: @Injectable() is a decorator that marks a
class as available to be provided and injected as a dependency.

18. What are Angular lifecycle hooks? Answer: Lifecycle hooks are methods in a component or directive that
Angular calls at different stages of the component’s lifecycle, such as ngOnInit(), ngOnDestroy(), and
ngOnChanges().

19. What is Angular's ngModel? Answer: ngModel is a directive used for two-way data binding between form
controls and the component data.

20. How do you implement custom validators in Angular forms? Answer: Custom validators can be implemented
by creating a function that returns either null or an object with validation errors and then adding it to the form
controls.

Intermediate Level

21. What are Angular Guards? Answer: Guards are used to control access to routes. They can prevent or allow
navigation based on certain conditions using interfaces like CanActivate, CanDeactivate, Resolve, and CanLoad.

22. What is lazy loading in Angular? Answer: Lazy loading is a technique used to load feature modules only when
they are needed, reducing the initial load time of the application.

23. How do you handle HTTP requests in Angular? Answer: HTTP requests are handled using the HttpClient
module, which provides methods like get(), post(), put(), and delete() for making HTTP requests.

24. What is the purpose of @NgModule decorator? Answer: @NgModule decorator defines an Angular module,
including declarations, imports, exports, and providers.

25. What is a singleton service in Angular? Answer: A singleton service is a service that is instantiated only once
during the lifetime of an Angular application, making it a shared instance across the application.

26. How do you implement pagination in Angular? Answer: Pagination can be implemented using third-party
libraries like ngx-pagination or by manually creating pagination logic and displaying data accordingly.

27. What is Angular Universal? Answer: Angular Universal is a server-side rendering (SSR) engine for Angular
applications, allowing for better performance and SEO by rendering the application on the server.

28. How do you manage state in Angular applications? Answer: State management can be handled using libraries
like NgRx or Akita, or through simpler techniques using Angular services and behavior subjects.

29. What is a Subject in Angular's RxJS? Answer: A Subject is a type of observable that allows values to be
multicasted to many observers. It can act as both an observer and an observable.

30. How do you handle errors in Angular applications? Answer: Errors can be handled using Angular's
ErrorHandler class or by catching errors in the HttpInterceptor for HTTP requests.

31. What is Angular's ChangeDetectionStrategy? Answer: ChangeDetectionStrategy defines how change


detection is performed. The two main strategies are Default and OnPush.

32. How do you create custom Angular directives? Answer: Custom directives are created by defining a class with
the @Directive decorator and specifying the directive's behavior and selector.

33. What is a pipe in Angular and how is it different from a directive? Answer: A pipe is used for transforming
data in templates, while a directive is used to manipulate the DOM or add behavior to elements.

34. How do you use Angular’s Dependency Injection system? Answer: Angular’s DI system is used to inject
dependencies into components or services by declaring them in the constructor and specifying them in the
providers array of modules or components.
35. What are Angular Animations and how do you use them? Answer: Angular Animations provide a way to
animate elements and transitions in the application using the @angular/animations package and Angular's
animation API.

36. How do you optimize Angular applications for performance? Answer: Performance can be optimized by
techniques such as lazy loading, using trackBy in ngFor, avoiding complex expressions in templates, and using
Angular's built-in tools for profiling and performance analysis.

37. What is the purpose of Angular's @Input and @Output decorators? Answer: @Input allows a parent
component to pass data to a child component, while @Output allows a child component to emit events to the
parent component.

38. What is Angular’s ng-content? Answer: ng-content is a directive used to project content into a component
from its parent component, allowing for content projection.

39. What are Angular services and how do they differ from components? Answer: Services are used to
encapsulate business logic and data access, while components are used to define the user interface and
behavior. Services are often injected into components to share data and functionality.

40. How do you implement authentication and authorization in Angular? Answer: Authentication and
authorization can be implemented using Angular guards, services, and libraries like Auth0 or Firebase for
handling user authentication and protecting routes.

Advanced Level

41. What is Angular's [Link] and when should it be used? Answer:


[Link] improves performance by only checking for changes when the input
properties change or when events are fired, suitable for optimizing complex applications.

42. How do you create a dynamic component in Angular? Answer: Dynamic components can be created using
ComponentFactoryResolver to instantiate and insert components at runtime.

43. What is the Angular Ivy renderer? Answer: Ivy is Angular's rendering engine introduced to improve
performance, reduce bundle sizes, and enable new features like better debugging and dynamic component
loading.

44. How do you manage global state in Angular applications? Answer: Global state management can be achieved
using state management libraries like NgRx
Here are 50 questions and answers about Object-Oriented Programming (OOP) concepts, categorized from beginner
to intermediate levels, useful for preparing for an Accenture interview.

Beginner Level

1. What is Object-Oriented Programming (OOP)? Answer: OOP is a programming paradigm based on the
concept of "objects," which can contain data in the form of fields (attributes) and code in the form of methods
(functions). It aims to improve code reusability and organization.

2. What are the four main principles of OOP? Answer: The four main principles are:

o Encapsulation

o Abstraction

o Inheritance

o Polymorphism

3. What is encapsulation in OOP? Answer: Encapsulation is the practice of bundling data and methods that
operate on that data within a single unit or class, and restricting access to some of the object's components.

4. What is abstraction in OOP? Answer: Abstraction is the concept of hiding the complex implementation details
and showing only the essential features of an object. It helps in reducing complexity.

5. What is inheritance in OOP? Answer: Inheritance is a mechanism where a new class (subclass or derived class)
is created based on an existing class (superclass or base class), inheriting its attributes and methods.

6. What is polymorphism in OOP? Answer: Polymorphism allows objects to be treated as instances of their
parent class rather than their actual class. It enables a single function or method to operate in different ways
depending on the object it is applied to.

7. What is a class in OOP? Answer: A class is a blueprint or template for creating objects. It defines a set of
attributes and methods that the created objects will have.

8. What is an object in OOP? Answer: An object is an instance of a class. It encapsulates data and behavior related
to that data as defined by the class.

9. What is a constructor in a class? Answer: A constructor is a special method that is automatically called when
an object is created. It initializes the object's attributes.

10. What is a method in OOP? Answer: A method is a function defined inside a class that operates on the
attributes of the class and can be used to perform operations on objects.

11. What is the difference between a class and an object? Answer: A class is a blueprint for creating objects,
whereas an object is an instance of a class, representing a specific realization of that class.

12. What is a superclass and a subclass? Answer: A superclass is a parent class from which other classes
(subclasses) inherit properties and methods. A subclass is a derived class that inherits from a superclass.

13. What is method overloading? Answer: Method overloading is the ability to define multiple methods with the
same name but different parameters within a class.

14. What is method overriding? Answer: Method overriding occurs when a subclass provides a specific
implementation of a method that is already defined in its superclass.

15. What is the difference between public, private, and protected access modifiers? Answer:

o public: Members are accessible from any other class.

o private: Members are accessible only within the class itself.

o protected: Members are accessible within the class and its subclasses.
16. What is the purpose of the super keyword? Answer: The super keyword is used to refer to the superclass's
methods and constructors from within a subclass.

17. What is a static method in OOP? Answer: A static method belongs to the class rather than any specific instance
and can be called without creating an instance of the class.

18. What is a static variable in OOP? Answer: A static variable is shared among all instances of a class. It is
initialized only once and can be accessed using the class name.

19. What is an interface in OOP? Answer: An interface is a reference type that defines a contract of methods that
implementing classes must provide. It cannot contain any implementation.

20. What is an abstract class? Answer: An abstract class is a class that cannot be instantiated on its own and may
contain abstract methods (methods without implementation) that must be implemented by subclasses.

Intermediate Level

21. How does encapsulation improve code security? Answer: Encapsulation restricts direct access to an object's
data and methods, protecting the object's state and ensuring that it can only be modified through well-defined
interfaces.

22. What is composition in OOP? Answer: Composition is a design principle where a class is composed of one or
more objects from other classes, rather than inheriting from them. It represents a "has-a" relationship.

23. What is the difference between composition and inheritance? Answer: Inheritance represents an "is-a"
relationship (a subclass is a type of superclass), while composition represents a "has-a" relationship (a class
has instances of other classes).

24. How does polymorphism enable code reusability? Answer: Polymorphism allows methods to operate on
objects of different types through a common interface, reducing the need for multiple implementations and
making code more flexible and reusable.

25. What is dynamic dispatch? Answer: Dynamic dispatch is the process of selecting which implementation of a
polymorphic method to call at runtime based on the object's actual type.

26. What is the difference between interface and abstract class? Answer: An interface can only define method
signatures without implementation, while an abstract class can provide both abstract methods and concrete
implementations.

27. What is the purpose of the final keyword in OOP? Answer: The final keyword is used to restrict the
modification of classes, methods, or variables:

o final class cannot be subclassed.

o final method cannot be overridden.

o final variable cannot be reassigned.

28. What is the Liskov Substitution Principle (LSP)? Answer: The Liskov Substitution Principle states that objects
of a superclass should be replaceable with objects of a subclass without affecting the correctness of the
program.

29. What is the Dependency Inversion Principle (DIP)? Answer: The Dependency Inversion Principle is a design
principle that states high-level modules should not depend on low-level modules but both should depend on
abstractions.

30. What is the Single Responsibility Principle (SRP)? Answer: The Single Responsibility Principle states that a
class should have only one reason to change, meaning it should only have one responsibility or job.
31. What is the Open/Closed Principle (OCP)? Answer: The Open/Closed Principle states that software entities
(classes, modules, functions) should be open for extension but closed for modification, allowing new
functionality to be added without altering existing code.

32. What is a design pattern? Answer: A design pattern is a reusable solution to a common problem in software
design. Examples include Singleton, Factory, and Observer patterns.

33. What is the Factory Method pattern? Answer: The Factory Method pattern defines an interface for creating
objects but allows subclasses to alter the type of objects that will be created.

34. What is the Singleton pattern? Answer: The Singleton pattern ensures a class has only one instance and
provides a global point of access to that instance.

35. What is the Observer pattern? Answer: The Observer pattern defines a one-to-many dependency between
objects so that when one object changes state, all its dependents are notified and updated automatically.

36. What is the Strategy pattern? Answer: The Strategy pattern defines a family of algorithms, encapsulates each
one, and makes them interchangeable. It allows algorithms to be selected at runtime.

37. What is the Adapter pattern? Answer: The Adapter pattern allows incompatible interfaces to work together
by converting the interface of a class into another interface that clients expect.

38. What is the Decorator pattern? Answer: The Decorator pattern adds new functionality to an object
dynamically without altering its structure, providing an alternative to subclassing for extending behavior.

39. What is the Command pattern? Answer: The Command pattern encapsulates a request as an object, thereby
allowing for parameterization of clients with queues, requests, and operations.

40. What is the Composite pattern? Answer: The Composite pattern allows individual objects and compositions
of objects to be treated uniformly, supporting the creation of tree structures.

41. What is a virtual method? Answer: A virtual method is a method defined in a base class that can be overridden
in a derived class, allowing for dynamic method dispatch.

42. What is method hiding? Answer: Method hiding occurs when a subclass defines a method with the same
name as one in its superclass, using the static keyword. The subclass's method hides the superclass's method
rather than overriding it.

43. What is a class hierarchy? Answer: A class hierarchy is an arrangement of classes in a parent-child relationship,
where subclasses inherit attributes and methods from their superclasses.

44. How do you achieve method chaining in OOP? Answer: Method chaining is achieved by having methods
return the object itself (this), allowing multiple methods to be called in a single statement.

45. What is encapsulation in terms of access modifiers? Answer: Encapsulation uses access modifiers (public,
private, protected) to control the visibility and access to the data and methods of a class, ensuring controlled
access and modification.

46. What is the difference between shallow copy and deep copy? Answer: A shallow copy creates a new object
but inserts references to the objects found in the original, while a deep copy creates a new object and
recursively copies all objects found in the original.

47. What is a constructor chaining? Answer: Constructor chaining is the process of calling one constructor from
another constructor within the same class or from a superclass.

48. What is a destructor in OOP? Answer: A destructor is a method called when an object is destroyed or goes
out of scope. It is used to clean up resources and perform necessary finalization.

49. What is an abstract method? Answer: An abstract method is a method declared in an abstract class that does
not have an implementation. Subclasses are required to provide an implementation for this method.
50. What is a sealed class? Answer: A sealed class is a class that cannot be inherited. It is used to prevent further
extension of the class.

You might also like