Top 50+ CSharp Asked Question in Interview
- Object-Oriented: C# supports the principles of object-oriented programming (OOP), allowing developers to create reusable and modular code through classes and objects.
- Type-Safe: C# is a statically-typed language, which means that type checking is done at compile time, reducing the chances of runtime errors.
- Interoperability: C# provides seamless interoperability with other languages like C, C++, and Visual Basic, making it easier to integrate existing codebases.
- Memory Management: C# includes automatic memory management through garbage collection, which helps in deallocating memory when objects are no longer in use.
- Modern Language Features: C# continues to evolve with modern language features like async/await for asynchronous programming, LINQ for querying data, and more.
using System; class Program { static void Main() { Console.WriteLine("Hello, World!"); } }
In this code snippet:
using System; imports the System namespace, which contains essential types and methods.
class Program defines a class named Program.
static void Main() is the entry point of the program.
Console.WriteLine("Hello, World!"); prints "Hello, World!" to the console.
C# is a versatile language that continues to be a popular choice for developers due to its robust features, performance, and extensive ecosystem. Whether you are a beginner or an experienced developer, mastering C# can open up a world of opportunities in software development.
public class MyClass { public static int myStaticVariable = 10; public static void MyStaticMethod() { Console.WriteLine("Static method called."); } }
Public :
The public keyword in C# is an access modifier that specifies that the associated member (class, method, property, etc.) is accessible from any other code in the same assembly or another assembly that references it. It provides the highest level of visibility. Public members can be accessed from outside the class in which they are defined.
public class MyClass { public int myPublicVariable = 20; public void MyPublicMethod() { Console.WriteLine("Public method called."); } }
Void :
In C#, void is a keyword used to specify that a method does not return a value. When a method is declared with a return type of void, it means that the method performs an action but does not produce a result that can be used in further computations. Void methods are commonly used for actions like printing output, updating variables, or performing operations without returning a value.
public class MyClass { public void MyVoidMethod() { Console.WriteLine("Void method called."); } }
In summary, static defines members that are shared across all instances of a class, public specifies that members are accessible from any code, and void indicates that a method does not return a value. Understanding these keywords is crucial for writing efficient and maintainable C# code.
// Define a class public class Car { public string Make { get; set; } public string Model { get; set; } public void Start() { Console.WriteLine("The car is starting..."); } } // Create an object of the Car class Car myCar = new Car(); myCar.Make = "Toyota"; myCar.Model = "Camry"; // Access object properties and methods Console.WriteLine($"My car is a {myCar.Make} {myCar.Model}"); myCar.Start();
In this example, Car is a class that defines the structure and behavior of a car object. By instantiating myCar from the Car class, we create a specific car object with its own Make, Model, and Start() method.
Objects in C# encapsulate data (attributes) and behavior (methods) within a single unit, promoting modularity and abstraction. They enable developers to model complex systems by breaking them down into manageable, reusable components.
Furthermore, objects interact with each other through methods and properties, facilitating communication and collaboration within the program. This interaction forms the basis of OOP principles such as inheritance, polymorphism, and encapsulation.
- public: Allows access from any other code in the same assembly or another assembly.
- private: Restricts access to only within the containing type.
- protected: Permits access within the containing type and derived types.
- internal: Grants access within the same assembly.
- protected internal: Combines the behavior of protected and internal, allowing access within the same assembly and derived types.
using System; public class Person { public string Name { get; set; } public int Age { get; set; } public void Introduce() { Console.WriteLine($"Hello, my name is {Name} and I am {Age} years old."); } } class Program { static void Main() { Person person1 = new Person(); person1.Name = "Alice"; person1.Age = 30; person1.Introduce(); } }
In this example, the Person class defines properties Name and Age, as well as a method Introduce to display information about a person. The Main method creates an instance of the Person class and calls the Introduce method to output a message.
In this example, Shape is an abstract class with an abstract method Area(). The Circle class inherits from Shape and implements the Area() method to calculate the area of a circle.
const int MaxValue = 100;
Read-only :
Read-only variables are declared using the readonly keyword and can be assigned a value either at the time of declaration or within the constructor of the class. Unlike constants, read-only variables can have different values for different instances of a class. They are typically used when the value needs to be determined at runtime or when different instances of a class need different values.
Here's an example of declaring a read-only variable in C#:
readonly int MaxValue; public MyClass(int value) { MaxValue = value; }
public sealed class SealedClass { public void DisplayMessage() { Console.WriteLine("This is a sealed class."); } } // This will result in a compilation error since you cannot inherit from a sealed class // public class DerivedClass : SealedClass // { // // Some code here // }
Sealed classes are often used when you want to restrict the inheritance of a class to maintain control over the class's behavior and prevent unintended modifications by subclasses. By sealing a class, you ensure that its implementation remains intact and cannot be altered by other classes.
It's important to note that not all classes need to be sealed. Sealing a class should be a deliberate decision based on the design and requirements of your application. In general, it is recommended to use sealed classes sparingly and only when necessary to enforce specific design constraints.
- Method Signature: In C#, method overloading is determined by the method signature, which includes the method name and the parameter list. Two methods with the same name but different parameter lists can coexist in the same class.
- Parameter Types: Overloaded methods must have different parameter types or a different number of parameters. C# compiler differentiates between overloaded methods based on the number and types of parameters they accept.
- Return Type: The return type of the method does not play a role in method overloading. Methods can have the same name and parameter list but different return types, as long as the parameter list is distinct.
In the example above, the Calculator class demonstrates method overloading with the Add method. Two Add methods exist in the Calculator class, one that accepts two integers and another that accepts two doubles. The compiler distinguishes between these methods based on the parameter types.
- Array: Arrays in C# are fixed in size and can only store elements of the same data type. Once an array is created, its size cannot be changed.
- ArrayList: ArrayLists, on the other hand, are dynamic and can store elements of different data types. They can grow or shrink in size dynamically.
- Array: Arrays offer better performance compared to ArrayLists because arrays are directly accessed by index, making them faster for element retrieval.
- ArrayList: ArrayLists are slower than arrays because they involve boxing and unboxing operations when adding or retrieving elements.
- Array: Arrays are less flexible as their size is fixed. If more elements need to be added beyond the initial size, a new array must be created, and elements must be copied over.
- ArrayList: ArrayLists are more flexible as they can dynamically resize themselves, making it easier to add or remove elements without manual resizing.
- Array: Arrays are type-safe, meaning they enforce type checking at compile time, ensuring that only elements of the specified type can be added.
- ArrayList: ArrayLists are not type-safe since they can store elements of different types without compile-time type checking.
- Array: Arrays are suitable when the number of elements is known in advance and remains constant throughout the program.
- ArrayList: ArrayLists are useful when the number of elements is not known beforehand or when dynamic resizing is required.
int[] numbers = new int[5]; // Declaration of an integer array with a size of 5
2- Lists: Lists are dynamic collections that can grow or shrink in size. The List<T> class in C# provides a resizable array implementation. Lists offer flexibility in adding, removing, and accessing elements.
List<string> names = new List<string>(); // Declaration of a list of strings names.Add("Alice"); names.Add("Bob");
3- Dictionaries: Dictionaries store key-value pairs, allowing you to access elements by a unique key. The Dictionary<TKey, TValue> class in C# provides a key-value mapping implementation.
Dictionary<int, string> keyValuePairs = new Dictionary<int, string>(); // Declaration of a dictionary keyValuePairs.Add(1, "One"); keyValuePairs.Add(2, "Two");
4- Sets: Sets store unique elements without duplicates. The HashSet<T> class in C# represents a collection of unique elements.
HashSet<int> uniqueNumbers = new HashSet<int>(); // Declaration of a set of integers uniqueNumbers.Add(1); uniqueNumbers.Add(2);
5- Queues and Stacks: Queues and stacks are specialized collections that follow the First-In-First-Out (FIFO) and Last-In-First-Out (LIFO) principles, respectively. The Queue<T> and Stack<T> classes in C# provide implementations for these data structures.
Queue<string> queue = new Queue<string>(); // Declaration of a queue queue.Enqueue("First"); queue.Enqueue("Second"); Stack<int> stack = new Stack<int>(); // Declaration of a stack stack.Push(1); stack.Push(2);
Benefits of Using Collections
- Flexibility: Collections offer flexibility in managing groups of objects with varying sizes and structures.
- Efficiency: Collections provide optimized algorithms for common operations like adding, removing, and searching elements.
- Type Safety: Strongly-typed collections ensure type safety, reducing runtime errors.
- Enhanced Functionality: Collections come with built-in methods and properties for convenient manipulation of data.
public class Calculator { public int Add(int a, int b) { return a + b; } public double Add(double a, double b) { return a + b; } }
In the above code snippet, the Add method is overloaded with different parameter types (int and double) to perform addition for both integer and double values.
Method Overriding:
Method overriding, on the other hand, is a feature that allows a subclass to provide a specific implementation of a method that is already provided by its superclass. This is achieved by creating a method in the subclass with the same signature as the method in the superclass. Method overriding is used to achieve runtime polymorphism. Here's an example illustrating method overriding in C#:
public class Shape { public virtual void Draw() { Console.WriteLine("Drawing a shape"); } } public class Circle : Shape { public override void Draw() { Console.WriteLine("Drawing a circle"); } }
In the above code snippet, the Circle class overrides the Draw method from the Shape class to provide a specific implementation for drawing a circle.
// Base class public class Animal { public void Eat() { Console.WriteLine("Animal is eating."); } } // Derived class inheriting from Animal public class Dog : Animal { public void Bark() { Console.WriteLine("Dog is barking."); } }
In this example, the Dog class inherits the Eat method from the Animal class. This allows Dog objects to access and use the Eat method along with its own Bark method.
public class MyClass { public int Number { get; set; } // Constructor public MyClass(int number) { Number = number; } } // Creating an instance of MyClass MyClass myObject = new MyClass(10);
In this example, the constructor initializes the Number property of the MyClass object when it is instantiated.In this example, the constructor initializes the Number property of the MyClass object when it is instantiated.
int number = 42; object boxedNumber = number; // Boxing occurs here
Unboxing:
Unboxing, on the other hand, is the process of extracting the value type from the object. It is the reverse operation of boxing. When you unbox, you are converting an object back to its original value type.
Here's an example of unboxing in C#:
object boxedNumber = 42; int unboxedNumber = (int)boxedNumber; // Unboxing occurs here
It's important to note that boxing and unboxing operations can impact performance, especially when done frequently in a codebase. Therefore, it's advisable to use them judiciously to avoid unnecessary overhead.
- Threads are the smallest sequence of programmed instructions that can be managed independently by a scheduler.
- They are part of the operating system and are managed by the OS kernel.
- Threads are low-level constructs and require more manual management.
- Threads are suitable for scenarios where you need fine-grained control over the execution flow.
- They are more lightweight than processes but can still consume significant system resources.
- Tasks are a higher-level abstraction introduced in the Task Parallel Library (TPL) in .NET.
- Tasks are managed by the .NET runtime and the TPL, providing a more abstract and easier-to-use model for parallelism.
- Tasks are based on the concept of the Task Parallel Library and are more suitable for asynchronous operations and parallel processing.
- Tasks can be easily composed, chained, and cancelled, making asynchronous programming more manageable.
- Tasks utilize thread pooling under the hood, allowing for efficient use of system resources.
- Abstraction Level: Threads are lower-level constructs managed by the OS, while tasks are a higher-level abstraction provided by the TPL.
- Management: Threads require more manual management, while tasks are managed by the .NET runtime and TPL.
- Ease of Use: Tasks provide a more user-friendly and composable model compared to threads.
- Cancellation: Tasks support cancellation mechanisms out of the box, making asynchronous operations easier to control.
- Resource Utilization: Tasks utilize thread pooling for efficient resource management, while threads can be more resource-intensive.
In this example, Creator declares the factory method FactoryMethod, and concrete creators ConcreteCreatorA and ConcreteCreatorB implement this method to create instances of ConcreteProductA and ConcreteProductB, respectively.
By using the Factory Method pattern, you can easily extend your code by adding new product types without modifying existing code, making it a powerful tool for managing object creation in a flexible and scalable way.
condition ? expression1 : expression2;
For example, consider the following code snippet:
int x = 10; string result = (x > 5) ? "x is greater than 5" : "x is less than or equal to 5"; Console.WriteLine(result);
In this example, if the condition (x > 5) is true, the value "x is greater than 5" will be assigned to the result variable; otherwise, "x is less than or equal to 5" will be assigned.
The ternary operator is handy for writing compact conditional statements, especially when assigning values based on a condition. However, it is essential to use it judiciously to maintain code readability and avoid complex nested ternary expressions that may reduce code clarity.
for (int i = 0; i < 5; i++) { // Code block to be executed }
2. do-while Loop:
The do-while loop is similar to the while loop but with a crucial difference: it always executes the code block at least once before checking the condition. This loop is useful when you want to ensure the code block runs at least once.
int i = 0; do { // Code block to be executed i++; } while (i < 5);
3. while Loop:
The while loop executes a block of code as long as the specified condition is true. It is suitable when the number of iterations is not known beforehand and the loop may not run at all if the condition is initially false.
int i = 0; while (i < 5) { // Code block to be executed i++; }
4. foreach Loop:
The foreach loop is specifically designed for iterating over collections such as arrays, lists, or other enumerable objects. It simplifies the process of iterating through elements without needing an explicit index.
int[] numbers = { 1, 2, 3, 4, 5 }; foreach (int number in numbers) { // Code block to be executed }
the choice of loop type depends on the specific requirements of your code. Understanding the differences between for, do-while, while, and foreach loops enables you to select the most appropriate loop construct for your programming needs.
public class MyClass { public static int staticField = 10; public static void StaticMethod() { Console.WriteLine("This is a static method."); } } class Program { static void Main() { // Accessing static field int value = MyClass.staticField; // Calling static method MyClass.StaticMethod(); } }
In the example above, staticField and StaticMethod are static members of the MyClass class. They can be accessed directly using the class name without creating an instance of MyClass.
using System; class Program { static void Main() { try { int x = 10; int y = 0; int result = x / y; // This will throw a DivideByZeroException } catch (DivideByZeroException ex) { Console.WriteLine("Error: " + ex.Message); } } }
In this example, a DivideByZeroException is caught and handled by the catch block, preventing the program from crashing. By understanding exceptions and implementing proper exception handling, developers can write more robust and reliable C# applications.
using System; // Declare a delegate delegate void PrintMessage(string message); class Program { static void Main() { // Instantiate the delegate with a method PrintMessage printDelegate = new PrintMessage(PrintHello); // Call the method indirectly through the delegate printDelegate("Hello, Delegates!"); } static void PrintHello(string message) { Console.WriteLine(message); } }
In this example, we define a delegate PrintMessage that can reference methods with a matching signature. We then create an instance of the delegate and assign it to the PrintHello method. Finally, we invoke the method indirectly through the delegate, resulting in the message "Hello, Delegates!" being printed to the console.
Delegates play a crucial role in achieving decoupling and flexibility in C# applications by allowing methods to be treated as first-class citizens. They are widely used in event handling, LINQ, and multithreading scenarios to provide a powerful mechanism for invoking methods dynamically.
public class Person { private string _name; public string Name { get { return _name; } set { _name = value; } } }
In this example, the Person class has a property Name that encapsulates the private field _name. The get accessor returns the current value of _name, and the set accessor allows setting a new value to _name.
Properties provide a more flexible and secure way to expose fields in a class, enabling you to enforce validation rules, computed properties, or access control. They play a crucial role in maintaining the integrity of the class's data and promoting good object-oriented design practices in C#.
using System; class Program { static int Add(int a, int b) { return a + b; // Return the sum of a and b } static void Main() { int result = Add(5, 3); Console.WriteLine("The sum is: " + result); } }
In this example, the Add method takes two integers as parameters, adds them together, and returns the result using the return statement. The Main method then calls Add with arguments 5 and 3, stores the returned value in result, and prints the sum to the console.
The return statement is crucial for controlling the flow of a program and providing output from methods or functions in C#.
for (int i = 0; i < 5; i++) { if (i == 3) { break; // exits the loop when i equals 3 } Console.WriteLine(i); }
2. continue Statement : -
The continue statement is also used in loops. When encountered, it skips the rest of the loop body and proceeds to the next iteration of the loop.
for (int i = 0; i < 5; i++) { if (i == 2) { continue; // skips the iteration when i equals 2 } Console.WriteLine(i); }
3. return Statement: -
The return statement is used to exit a method and return a value to the calling code. It transfers control back to the caller of the method.
int Add(int a, int b) { return a + b; // exits the method and returns the sum of a and b }
4. goto Statement: -
The goto statement allows transferring control to a labeled statement within the same method. However, the use of goto is generally discouraged due to its potential to make the code less readable and harder to maintain.
int i = 0; start: Console.WriteLine(i); i++; if (i < 5) { goto start; // jumps back to the start label }
5. throw Statement: -
The throw statement is used to raise exceptions explicitly. It transfers control to the nearest catch block in the call stack.
int Divide(int a, int b) { if (b == 0) { throw new DivideByZeroException(); // raises an exception } return a / b; }
int number = 10; if (number > 0) { Console.WriteLine("The number is positive."); }
2- On the other hand, nested if statements involve placing one if statement inside another. This allows for more complex conditional logic by checking multiple conditions sequentially. Each if statement is evaluated independently.
Here's an example of nested if statements:
int x = 10; int y = 20; if (x == 10) { if (y == 20) { Console.WriteLine("Both x and y are equal to their respective values."); } }
3- Lastly, the if-else ladder is used when you have multiple conditions to check, and each condition has a different block of code to execute. It starts with an if statement, followed by one or more else if statements, and ends with an optional else statement. The if-else ladder ensures that only one block of code is executed based on the first condition that is true.
Here's an example:
int num = 0; if (num > 0) { Console.WriteLine("The number is positive."); } else if (num < 0) { Console.WriteLine("The number is negative."); } else { Console.WriteLine("The number is zero."); }
- Arrays in C# are fixed in size, meaning the length of an array is determined at the time of creation and cannot be changed.
- Elements in an array must be of the same data type.
- Arrays offer better performance in terms of access speed compared to ArrayLists because they are directly accessed by index.
- Array elements are stored in contiguous memory locations, which can lead to better cache performance.
int[] numbers = new int[5]; // Creating an integer array of size 5
ArrayLists:
- ArrayLists, on the other hand, are dynamic and can grow or shrink in size dynamically.
- Elements in an ArrayList can be of different data types since ArrayList is a collection of objects.
- ArrayLists provide more flexibility in terms of adding, removing, and manipulating elements at runtime.
- ArrayLists are part of the System.Collections namespace and offer more functionalities compared to arrays.
Example of using an ArrayList in C#:
using System; using System.Collections; ArrayList list = new ArrayList(); list.Add(10); // Adding an integer list.Add("Hello"); // Adding a string
Arrays are suitable for situations where a fixed-size collection with a single data type is needed, while ArrayLists are more versatile and convenient for scenarios requiring dynamic resizing and heterogeneous elements. Each has its strengths and use cases, so choosing between them depends on the specific requirements of the application.
There are three types of serialization
- Binary serialization (Save your object data into binary format)
- Soap Serialization (Save your object data into binary format; mainly used in network-related communication).
- XmlSerialization (Save your object data into an XML file).
using System; using System.Collections; class Program { static void Main() { // Creating a new Hashtable Hashtable hashtable = new Hashtable(); // Adding key/value pairs to the Hashtable hashtable.Add("key1", "value1"); hashtable.Add("key2", "value2"); // Accessing values using keys Console.WriteLine(hashtable["key1"]); Console.WriteLine(hashtable["key2"]); } }
In the code snippet above, we create a Hashtable, add key/value pairs to it, and then retrieve values using their respective keys. Hashtables are useful for storing and accessing data efficiently, especially when quick lookups are required based on unique keys.
- Readability: LINQ enhances code readability by providing a declarative way to query data.
- Productivity: It simplifies querying data from various sources like collections, databases, XML, and more.
- Type Safety: LINQ queries are type-safe, catching errors at compile time rather than runtime.
- Intellisense Support: LINQ benefits from IDE features like Intellisense, aiding developers in writing queries efficiently.
- Code Reusability: LINQ promotes reusable query components, reducing redundant code.
- Performance Optimization: LINQ optimizes query execution, often outperforming traditional loops.
- Integration: LINQ seamlessly integrates with existing C# code, making it a powerful tool for data manipulation.
var person = new { Name = "John", Age = 30 }; Console.WriteLine($"Name: {person.Name}, Age: {person.Age}");
Anonymous Types provide a convenient way to work with data without the need for formal class definitions, enhancing code readability and flexibility in certain scenarios.
int[][] jaggedArray = new int[3][]; jaggedArray[0] = new int[] { 1, 2, 3 }; jaggedArray[1] = new int[] { 4, 5 }; jaggedArray[2] = new int[] { 6, 7, 8, 9 }; // Accessing elements in the Jagged Array Console.WriteLine(jaggedArray[0][1]); // Output: 2 Console.WriteLine(jaggedArray[1][0]); // Output: 4
In the example above, jaggedArray is a Jagged Array with three rows, where each row can have a different number of elements. Accessing elements in a Jagged Array involves using multiple indices to navigate through the rows and columns of the array.
Jagged Arrays provide a flexible way to represent and manipulate data structures that do not have a fixed size. They are commonly used in scenarios where the number of elements in each row varies, such as representing a collection of arrays with different lengths.
- Asynchronous Programming: Async and await enable developers to write asynchronous code more easily. Asynchronous programming allows tasks to run concurrently without blocking the main thread, enhancing the responsiveness and performance of applications.
- Non-Blocking Operations: By using async and await, developers can perform non-blocking operations such as I/O-bound tasks (e.g., reading from a file, making network requests) without halting the program's execution. This ensures that the application remains responsive during these operations.
- Improved Scalability: Asynchronous programming with async and await enhances the scalability of applications by efficiently utilizing system resources. Instead of waiting for a task to complete, the program can continue executing other tasks, leading to better resource management.
- Simplified Code Structure: Async and await simplify the structure of asynchronous code by allowing developers to write asynchronous operations in a more sequential and readable manner. This improves code maintainability and reduces complexity, making it easier to debug and enhance the codebase.
- Exception Handling: Async and await provide better support for exception handling in asynchronous code. Developers can use try-catch blocks to handle exceptions that occur during asynchronous operations, ensuring robust error management in asynchronous scenarios.
Each non-generic collection can be used to store different types as they are not strongly typed.
- ArrayList: Similar to an array, does not have a specific size, and can store any number of elements
- HashTable: Stores key-value pairs for each item, does not have a specific size, can store any number of elements, key objects must be immutable
- SortedList: Combination of ArrayList and HashTable, data stored as key-value pairs, items sorted by keys, items accessed by key or index, does not have a specific size, can store any number of elements
- Stack: Simple Last-In-First-Out (LIFO) structure, does not have a specific size, can store any number of elements, elements are pushed onto the stack and popped off from the stack
- Queue: First-In-First-Out (FIFO) structure, does not have a specific size, can store any number of elements, elements are enqueued into the queue and dequeued from the queue
class Shape { public virtual void Draw() { Console.WriteLine("Drawing a shape..."); } } class Circle : Shape { public override void Draw() { Console.WriteLine("Drawing a circle..."); } }
Method Overloading :-
Method overloading, on the other hand, allows a class to have multiple methods with the same name but different parameters. The compiler determines which method to call based on the number and types of arguments passed.
Here's an example:
class Calculator { public int Add(int a, int b) { return a + b; } public double Add(double a, double b) { return a + b; } }
- string: Immutable; any operation that appears to modify a string actually creates a new string.
- StringBuilder: Mutable; allows modification without creating new instances, making it more efficient for extensive string manipulation.
- string: Less efficient for concatenating multiple strings due to repeated memory allocations.
- StringBuilder: More efficient for concatenation operations, especially when dealing with large strings or frequent modifications.
- Use string when dealing with static or less frequently modified strings.
- Use StringBuilder when extensive string manipulation, concatenation, or modification is required to avoid unnecessary memory overhead.
public class ClientService { private readonly IClientRepository _clientRepository; public ClientService(IClientRepository clientRepository) { _clientRepository = clientRepository; } // Other methods using _clientRepository }
- terminate()
- sleep()
- suspend()
- stop()
- 0
- 1
- 2
- any number of values
- private
- final
- abstract
- public
- if (s1= s2)
- int c; c=s1.CompareTo(s2);
- if (strcmp(s1,s2))
- if(s1 is s2)
- float
- none of the mentioned
- int
- long
- sealed
- abstract
- static
- final
- Checks for nullability and returns the non-null value
- Compares two values
- Merges two values
- Assign one of two values depending on a condition
- MyClass myObj =new MyClass()
- class myObj = new MyClass()
- class MyClass = new myObj()
- new myObj=MyClass()
- It's a process in which two different process run simultaneously
- It's a process in which two or more parts of same process run simultaneously
- It's a process in which a single process can access information from many sources
- It's a process in which many different process are able to access same information
- Encapsulation
- Polymorphism
- None of the mentioned
- Abstraction
- None of the mentioned
- 2
- 1
- any number
- To control the visibility and accessibility of class members
- To maintain the syntax
- None of these
- To define a variable inside the class
- exit
- break
- return
- stop
- Stops exception from propagating
- Executes regardless of whether an exception is thrown or caught
- Throws exceptions
- Catches exceptions
- split()
- substr()
- search()
- slice()