h1.post-title { color:orange; font-family:verdana,Arial; font-weight:bold; padding-bottom:5px; text-shadow:#64665b 0px 1px 1px; font-size:32px; } -->

Pages

OOPS Questions and Answers Part I

OOPS Questions and Answers:

Part I
1)   What is OOPS?
OOPS is abbreviated as Object Oriented Programming system in which programs are considered as a collection of objects. Each object is nothing but an instance of a class.

2) Write basic concepts of OOPS?
Following are the concepts of OOPS and are as follows:.
  1. Abstraction.
  2. Encapsulation.
  3. Inheritance.
  4. Polymorphism.

3)  What is a class?
Class is a collection of the object, and it has common structure and behavior.

4)  What is an object?
Object is termed as an instance of a class, and it has its own state, behavior and identity.

5)  What is Encapsulation?
Encapsulation is an attribute of an object, and it contains all data which is hidden. That hidden data can be restricted to the members of that class.
Levels are Public, Protected, Private, Internal and Protected Internal.

6) What is Polymorphism?
Polymorphism is nothing but assigning behavior or value in a subclass to something that was already declared in the main class. Simply, polymorphism takes more than one form.

7)  What is Inheritance?
Inheritance is a concept where one class shares the structure and behavior defined in another class. If inheritance applied on one class is called Single Inheritance, and if it depends on multiple classes, then it is called multiple Inheritances.

8)  What are manipulators?
Manipulators are the functions which can be used in conjunction with the insertion (<<) and extraction (>>) operators on an object.

9)  Define a constructor?
Constructor is a method used to initialize the state of an object, and it gets invoked at the time of object creation. Rules for constructor are:
  • Constructor Name should be same as class name.
  • Constructor must have no return type.

10)  Define Destructor?
Destructor is a method which is automatically called when the object is made of scope or destroyed. Destructor name is also same as class name but with the tilde symbol before the name.

11) What is Inline function?
Inline function is a technique used by the compilers and instructs to insert complete body of the function wherever that function is used in the program source code.

12) What is a virtual function?
Virtual function is a member function of class and its functionality can be overridden in its derived class. This function can be implemented by using a keyword called virtual, and it can be given during function declaration.
Virtual function can be achieved in C++, and it can be achieved in C Language by using function pointers or pointers to function.

13.   What is friend function?
Friend function is a friend of a class that is allowed to access to Public, private or protected data in that same class. If the function is defined outside the class cannot access such information.
Friend can be declared anywhere in the class declaration, and it cannot be affected by access control keywords like private, public or protected.

14)  What is function overloading?
Function overloading is defined as a normal function, but it has the ability to perform different tasks. It allows creation of several methods with the same name which differ from each other by type of input and output of the function.
Example
void add(int& a, int& b);
void add(double& a, double& b);
void add(struct bob& a, struct bob& b);

15)   What is operator overloading?
Operator overloading is a function where different operators are applied and depends on the arguments. Operator,-,* can be used to pass through the function , and it has their own precedence to execute.
Example:
class complex {
double real, imag;
public:
complex(double r, double i) :
real(r), imag(i) {}
complex operator+(complex a, complex b);
complex operator*(complex a, complex b);
complex& operator=(complex a, complex b);
}
a=1.2, b=6

16)   What is an abstract class?
An abstract class is a class which cannot be instantiated. Creation of an object is not possible with abstract class, but it can be inherited. An abstract class can contain only Abstract method.

17)   What is a ternary operator?
Ternary operator is set to be an operator which takes three arguments. Arguments and results are of different data types, and it is depends on the function. Ternary operator is also called as conditional operator.

18)   What is the use of finalize method?
Finalize method helps to perform cleanup operations on the resources which are not currently used. Finalize method is protected, and it is accessible only through this class or by a derived class.

19)   What are different types of arguments?
A parameter is a variable used during the declaration of the function or subroutine and arguments are passed to the function , and it should match with the parameter defined. There are two types of Arguments.
  • Call by Value – Value passed will get modified only inside the function , and it returns the same value whatever it is passed it into the function.
  • Call by Reference – Value passed will get modified in both inside and outside the functions and it returns the same or different value.

20)   What is method overriding?
Method overriding is a feature that allows sub class to provide implementation of a method that is already defined in the main class. This will overrides the implementation in the super class by providing the same method name, same parameter and same return type.

21) What is an interface?
An interface is a collection of abstract method. If the class implements an inheritance, and then thereby inherits all the abstract methods of an interface.

22) What is exception handling?
Exception is an event that occurs during the execution of a program. Exceptions can be of any type – Run time exception, Error exceptions. Those exceptions are handled properly through exception handling mechanism like try, catch and throw keywords.

23)  Difference between overloading and overriding?
Overloading is static binding whereas Overriding is dynamic binding. Overloading is nothing but the same method with different arguments , and it may or may not return the same value in the same class itself.
Overriding is the same method names with same arguments and return types associates with the class and its child class.

24)  Difference between class and an object?
An object is an instance of a class. Objects hold any information , but classes don’t have any information. Definition of properties and functions can be done at class and can be used by the object .Class can have sub-classes, and an object doesn’t have sub-objects.

25)  What is an abstraction?
Abstraction is a good feature of OOPS , and it shows only the necessary details to the client of an object. Means, it shows only necessary details for an object, not the inner details of an object. Example – When you want to switch On television, it not necessary to show all the functions of TV. Whatever is required to switch on TV will be showed by using abstract class.

26)  What are access modifiers?
Access modifiers determine the scope of the method or variables that can be accessed from other various objects or classes. There are 5 types of access modifiers, and they are as follows:.
  •  Private.
  • Protected.
  • Public.
  • Friend.
  • Protected Friend.

27)  What is sealed modifiers?
Sealed modifiers are the access modifiers where it cannot be inherited by the methods. Sealed modifiers can also be applied to properties, events and methods. This modifier cannot be applied to static members.

28)   What is the difference between new and override?
The new modifier instructs the compiler to use the new implementation instead of the base class function. Whereas, Override modifier helps to override the base class function.

29)   What are the various types of constructors?
There are three various types of constructors, and they are as follows:.
·         Default Constructor – With no parameters.
·         Parametric Constructor – With Parameters. Create a new instance of a class and also passing arguments simultaneously.
·         Copy Constructor – This creates a new object as a copy of an existing object.

30)  What is early and late binding?
Early binding refers to assignment of values to variables during design time whereas late binding refers to assignment of values to variables during run time.

31)  What is the difference between structure and a class?
Structure default access type is public, but class access type is private. A structure is used for grouping data whereas class can be used for grouping data and methods. Structures are exclusively used for data and it doesn’t require strict validation, but classes are used to encapsulates and inherit data which requires strict validation.

32) What is dynamic or run time polymorphism?
Dynamic or Run time polymorphism is also known as method overriding in which call to an overridden function is resolved during run time, not at the compile time. It means having two or more methods with the same name, same signature but with different implementation.

33)   Whether static method can use non static members?
False.

34)  What are base class, sub class and super class?
Base class is the most generalized class, and it is set to be a root class.
Sub class is a class that inherits from one or more base classes.
Super class is another type of class from which another class inherits.

35) What is static and dynamic binding?
Binding is nothing but the association of a name with the class. Static binding is a binding in which name can be associated with the class during compilation time , and it is also called as early Binding.
Dynamic binding is a binding in which name can be associated with the class during execution time, and it is also called as Late Binding.
Thanks to Google

C# -- General Questions and Answers Part-II

C# -- General Questions and Answers:
Part-II
1)      Is it possible to use Keychar value in Keyup Event?
           Yes, Use Keyvalue.
Code
if (e.KeyValue == 13)
            {
                   MessageBox.Show("Press Enter Key");
            }
22)      Difference between Form_loading and Form_activated?
  Load: This event occurs before a form is displayed for the first time.
  Activated: This event occurs when the form is activated in code or by the user.
33)      What are the Keywords apply to event?
Keywords for Event: Static, Virtual, Sealed and Abstract.
44)      Which is a basis for event?
  Events:
 Form_Load, Click, Got_Focus (), Set_Focus(),Activate(),Form_Close()
55)      Where to use default keyword?
The default keyword is contextual since it has multiple usages. I am guessing that you are referring to its newer C# 2 meaning in which it returns a type's default value. For reference types this is null and for value types this new instance all zero'd out.
66)      Is it possible to change the const keyword object?
No, you will get this error "The left-hand side of an assignment must be a variable, property or indexer".
77)      Is static modifier allowed in a Constant Declaration? Why?
No, Static and const are not the same thing. Static means that you do not instantiate a class object in memory to use the static object.  Static objects can be changed.
Const means that you cannot change the value.
88)      Is it possible to use more catch statement in the Try catch statement?
  Yes,
                    try
                                         {
                                             //try connect to db
                    }
                    catch (SqlException ex)
                    {
                        // information of database related exception
                    }
                    catch (Exception ex)
                    {
                        // catch any other error
                    }

99)      What is the default value of bool value?
Boolean default is false
110)   How to stop long Thread?
Use Thread. Stop ();
111)   Which namespace has Threading?
Namespace of Threading is  System. Threading;
112)   How to get Default value in C#.net?
Use Default Keyword.
113)   When are validating and validated events suppressed?
CausesValidation Property is false.
114)   Difference between Double.Parse and Double.TryParse?
Parse throws an exception if it cannot parse the value
 TryParse returns a bool indicating whether it succeeded.
115)   What method do you call on a delegate to run it on a background thread?
  Invoke Method.
116)   What keyword provides thread synchronization?
   Lock Keyword.
117)   Where to use Delegates in C#.net?
Delegates are used in the following cases:
·         Event handlers
·         Callbacks
·         LINQ
·         Implementation of design patterns.
http://zetcode.com/lang/csharp/delegates/


C# -- General Questions and Answers Part-I



C# -- General Questions and Answers:

Part-I

1.  What is C#?
                    C# (pronounced "C sharp") is a simple, modern, object-oriented, and type-safe programming language. It will immediately be familiar to C and C++ programmers. C# combines the high productivity of Rapid Application Development (RAD) languages.

2.   What are the types of comment in C#?
            There are 3 types of comments in C#.  Single line (//)     Multi (/* */)     Page/XML Comments (///).

3.  What are the namespaces used in C#.NET?
          Namespace is a logical grouping of class.
    using System;
    using System.Collections.Generic;
    using System.Windows.Forms;

4.  What are the characteristics of C#?
     There are several characteristics of C# are:
v  Simple   
v  Type safe   
v  Flexible    
v  Object oriented    
v  Compatible    
v  Consistent     
v  Interoperable 
v  Modern

5. What are the modifiers in C#?
      Modifiers are:
v  Abstract
v  Sealed
v  Virtual
v  Const
v  Event
v  Extern
v  Override
v  Read only
v  Static
v  New
6.   What are the types of access modifiers in C#?
Access modifiers in C# are: 
v  Public
v  Protect
v  Private
v  Internal
v  internal protect
7.  What is boxing and unboxing?
                 Boxing: Convert Value Type to Reference Type.
Unboxing:  Convert Reference Type to Value Type.
8.  What are the types of arrays in C#?
              Types of Arrays:
v  Single-Dimensional
v  Multidimensional
v  Jagged arrays.

9. Define Constructors?
                A constructor is a member function with the same name as its class. The constructor is invoked whenever an object of its associated class is created. It is called constructor because it constructs the values of data members of the class.

10.  Define destructors?
                A destructor is called for a class object when that object passes out of scope or is explicitly deleted.
           A destructors as the name implies is used to destroy the objects that have been created by a constructors

11. What is ENUM?
                Enum are used to define constants.

12. What is the use of enumerated data type?
                An enumerated data type is another user defined type which provides a way for attaching names to numbers thereby increasing comprehensibility of the code. The Enum keyword automatically enumerates a list of words by assigning them values 0,1,2, and so on.

13. What is Jagged Arrays?         
    A jagged array is an array whose elements are arrays.
    The elements of a jagged array can be of different dimensions and sizes.
    A jagged array is sometimes called an array–of–arrays.

14. What is the use of using statement in C#?
                The using statement is used to obtain a resource, execute a statement, and then dispose of that resource.

15. What is serialization?
                Serialization is the process of converting an object into a stream of bytes.
De-serialization is the opposite process of creating an object from a stream of bytes.
Serialization / De-serialization is mostly used to transport objects.

16. What is a base class?
                A class declaration may specify a base class by following the class name with a colon and the name of the base class. Omitting a base class specification is the same as deriving from type object.

17. Can “this” be used within a static method?
                No ‘This’ cannot be used in a static method. As only static variables/methods can be used in a static method.

18. What are the different types of statements supported in C#?
               

    C# supports several different kinds of statements are
v  Block statements
v  Declaration statements
v  Expression statements
v  Selection statements
v  Iteration statements
v  Jump statements
v  Try catch statements
v  Checked and unchecked
v  Lock statement

19. What is method?
                A method is a member that implements a computation or action that can be performed by an object or class. Static methods are accessed through the class. Instance methods are accessed through instances of the class.

20. What is field?
                A field is a variable that is associated with a class or with an instance of a class.

21. What is event?
                An event is a member that enables a class or object to provide notifications. An event is declared like a field except that the declaration includes an event keyword and the type must be a delegate type.

22. What are literals and their types?
                    Literals are value constants assigned to variables in a program. C# supports several types of literals are
v  Integer literals
v  Real literals
v  Boolean literals
v  Single character literals
v  String literals
v  Backslash character literals

23. What are the features of c#?
v  C# is a simple and powerful programming language for writing enterprise edition applications.
v  This is a hybrid of C++ and VB. It retains many C++ features in the area statements, expressions, and operators and incorporated the productivity of VB.
v  C# helps the developers to easily build the web services that can be used across the Internet through any language, on any platform.
v  C# helps the developers accomplishing with fewer lines of code that will lead to the fewer errors in the code.
v  C# introduces the considerable improvement and innovations in areas such as type safety, versioning, events and garbage collections.

24.          What are the types of errors?
v  Syntax error
v  Logic error
v  Runtime error

25. What are the two data types available in C#?
v  Value type
v  Reference type

26. What is a code group?
                A code group is a set of assemblies that share a security context.

27. What are sealed classes in C#?
                The sealed modifier is used to prevent derivation from a class. A compile-time error occurs if a sealed class is specified as the base class of another class.

28. Define namespace?
                The namespace are known as containers which will be used to organize the hierarchical set of .Net classes.

29. What are the different types of variables in C#?
         Different types of variables used in C# are:
v  static variables
v  instance variable
v  value parameters
v  reference parameters
v  array elements
v  output parameters
v  local variables

30. What is meant by method overloading?
                Method overloading permits multiple methods in the same class to have the same name as long as they have unique signatures. When compiling an invocation of an overloaded method, the compiler uses overload resolution to determine the specific method to invoke

31. What is parameter?
                Parameters are used to pass values or variable references to methods. The parameters of a method get their actual values from the arguments that are specified when the method is invoked. There are four kinds of parameters: value parameters, reference parameters, output parameters, and parameter arrays.

32. Is C# is object oriented?
                YEs, C# is an OO language in the tradition of Java and C++.

33. What are the special operators in C#?
      C# supports the following special operators.
v  is (relational operator)
v  as (relational operator)
v  typeof (type operator)
v  sizeof (size operator)
v  new (object creator)
v  .dot (member access operator)
v  checked (overflow checking)
v  unchecked (prevention of overflow checking)

34. What is meant by operators in c#?
                An operator is a member that defines the meaning of applying a particular expression operator to instances of a class. Three kinds of operators can be defined: unary operators, binary operators, and conversion operators. All operators must be declared as public and static.

35. What is a parameterized type?
                A parameterized type is a type that is parameterized over another value or type.

36. What is the use of abstract keyword?
                The modifier abstract is a keyword used with a class, to indicate that this class cannot itself have direct instances or objects, and it is intended to be only a 'base' class to other classes.

37.  What is the use of goto statement?
                The goto statement is also included in the C# language. This goto can be used to jump from inside a loop to outside. But jumping from outside to inside a loop is not allowed.

38. Does C# have a throws clause?
                No, unlike Java, C# does not require the developer to specify the exceptions that a method can throw.

39. Does C# support a variable number of arguments?
                Yes, using params keyword. The arguments are specified as a list of arguments of a specific type.

40. Can you override private virtual methods?
                No, private methods are not accessible outside the class.

41. What is a multi cast delegates?
                Each delegate object holds reference to a single method. However, it is possible for a delegate object to hold references of and invoke multiple methods. Such delegate objects are called multicast delegates or combinable delegates.

42. Which is an exclusive feature of C#?
                Xml documentation.

43. Is using of exceptions in C# recommended?
                Yes, exceptions are the recommended error handling mechanism in .NET Framework.

44. What does a break statement do in switch statements?
    The break statement terminates the loop in which it exists. It also changes the flow of the execution of a program.
    In switch statements, the break statement is used at the end of a case statement. The break statement is mandatory in C# and it avoids the fall through of one case statement to another.
45. What is smart navigation?
                The cursor position is maintained when the page gets refreshed due to the server side validation and the page gets refreshed.

46. What is an identifier?
                Identifiers are nothing but names given to various entities uniquely identified in a program.

47. What is the use of return statement?
    The return statement is associated with procedures (methods or functions). On executing the return statement, the system passes the control from the called procedure to the calling procedure. This return statement is used for two purposes:
v  to return immediately to the caller of the currently executed code
v  to return some value to the caller of the currently executed code.

48. What are the different ways a method can be overloaded?
                Different parameter data types, different number of parameters, different order of parameters.

49. Do events have return type?
                No, events do not have return type.

49. What are the different types of literals in C#?
v  Boolean literals: True and false are literals of the Boolean type that map to the true and false state, respectively.
v  Integer literals: Used to write values of types Int, uint, long, and ulong.
v  Real literals: Used to write values of types float, double, and decimal.
v  Character literals: Represents a single character and usually consists of a character in quotes, such as 'a'.
v  String literals: C# supports two types of string literals, regular string literal and verbatim string literals. A regular string literal consists of zero or more characters enclosed in double quotes, such as "116110". A verbatim string literal consists of an @ character followed by a double–quote character, such as ©"hello".
v  The Null literal: Represents the null–type.

50. Can you override private virtual methods?
                No. Private methods are not accessible outside the class.

51. What is nested class?
    A Nested classes are classes within classes.
    A nested class is any class whose declaration occurs within the body of another class or interface.

52. Can you have parameters for static constructors?
                No, static constructors cannot have parameters.

53. Is String is Value Type or Reference Type in C#?
                String is an object (Reference Type).

54. Does C# provide copy constructor?
                No, C# does not provide copy constructor.
55. Can a class have static constructor?
                Yes, a class can have static constructor. Static constructors are called automatically, immediately before any static fields are accessed, and are generally used to initialize static class members. It is called automatically before the first instance is created or any static members are referenced. Static constructors are called before instance constructors. An example is shown below.

56. What is the main use of delegates in C#?
                Delegates are mainly used to define call back methods.

57. Can events have access modifiers?
                Yes, you can have access modifiers in events. You can have events with the protected keyword, which will be accessible only to inherited classes. You can have private events only for objects in that class.

58. Why is the virtual keyword used in code?
                The Virtual keyword is used in code to define methods and the properties that can be overridden in derived classes.

59. How can we suppress a finalize method?
                GC.SuppressFinalize ()

60. Does C# support a variable number of arguments?
    Yes, using the params keyword.
    The arguments are specified as a list of arguments of a specific type, e.g., int. For ultimate flexibility, the type can be object.
    The standard example of a method which uses this approach is System.console.writeLine ().

61. Which method will you call to start a thread?
                Start

62. What is Generic?
    Generic help us to create flexible strong type collection.
    Generic basically separate the logic from the data type in order maintain better reusability, better maintainability etc.

63. Which namespace enables multithreaded programming in XML?
                System. Threading

64. Can we declare a block as static in c#?
                No, because c# does not support static block, but it supports static method.

65. Can we declare a method as sealed?
                In C# a method can't be declared as sealed. However when we override a method in a derived class, we can declare the overridden method as sealed. By declaring it as sealed, we can avoid further overriding of this method.

66. What Command is used to implement properties in C#?
                Get & set access modifiers are used to implement properties in c#.
67. What is static member?
                The member defined as static which can be invoked directly from the class level, rather than from its instance.

68. What is Static Method?
                It is possible to declare a method as Static provided that they don't attempt to access any instance data or other instance methods.

69. What is a new modifier?
                The new modifier hides a member of the base class. C# supports only hide by signature.

70. What are the advantages of get and set properties in C#? 
v  The get property accessor is used to return the property value.
v  The set property accessor is used to assign a new value.

71.  Can multiple catch blocks be executed?
No, Multiple catch blocks can’t be executed. Once the proper catch code executed, the control is transferred to the finally block and then the code that follows the finally block gets executed

72. How can we sort the elements of the array in descending order?
Using Sort () methods followed by Reverse () method.

73. Write down the C# syntax to catch exception?
To catch an exception, we use try catch blocks. Catch block can have parameter of system. Exception type.
E.g.
?
1
2
3
4
5
6
7
try
{
GetAllData();
}
catch(Exception ex)
{
}

74.   What are circular references?
Circular reference is situation in which two or more resources are interdependent on each other causes the lock condition and make the resources unusable.

75.   What are generics in C#.NET?
Generics are used to make reusable code classes to decrease the code redundancy, increase type safety and performance. Using generics, we can create collection classes. To create generic collection, System.Collections.Generic namespace should be used instead of classes such as Arraylist in the System. Collections namespace. Generics promote the usage of parameterized types.

76.   What is an object pool in .NET?
An object pool is a container having objects ready to be used. It tracks the object that is currently in use, total number of objects in the pool. This reduces the overhead of creating and re-creating objects.

77. List down the commonly used types of exceptions in .Net?
v  ArgumentException
v  ArgumentNullException
v  ArgumentOutOfRangeException
v  ArithmeticException,
v  DivideByZeroException
v  OverflowException
v  IndexOutOfRangeException
v  InvalidCastException
v  InvalidOperationException
v  IOEndOfStreamException
v  NullReferenceException
v  OutOfMemoryException
v  StackOverflowException etc.

78. What are Custom Exceptions?
Sometimes there are some errors that need to be handled as per user requirements. Custom exceptions are used for them and are used defined exceptions.

 79. What are indexers in C# .NET?
Indexers are known as smart arrays in C#. It allows the instances of a class to be indexed in the same way as array.
E.g.

public int this[int index]    // Indexer declaration



80. Is C# code is managed or unmanaged code?
C# is managed code because Common language runtime can compile C# code to Intermediate language.

81. What are the ways to deploy an assembly?
An MSI installer, a CAB archive, and XCOPY command.

82. What’s a satellite assembly?
When you write a multilingual or multi-cultural application in .NET, and want to distribute the core application separately from the localized modules, the localized assemblies that modify the core application are called satellite assemblies.

83. What namespaces are necessary to create a localized application?
System. Globalization, System. Resources.

84. How do you generate documentation from the C# file commented properly with a command-line compiler?
Compile it with a /doc switch.

85. Is XML case-sensitive?
Yes, so and are different elements.

86. What debugging tools come with the .NET SDK?
CorDBG – command-line debugger, and DbgCLR – graphic debugger. Visual Studio .NET uses the DbgCLR. To use CorDbg, you must compile the original C# file using the /debug switch.

87. What does the this window show in the debugger?
It points to the object that’s pointed to by this reference. Object’s instance data is shown.

88. What does assert () do?
In debug compilation, assert takes in a Boolean condition as a parameter, and shows the error dialog if the condition is false. The program proceeds without any interruption if the condition is true.

89. Why are there five tracing levels in System.Diagnostics.TraceSwitcher?
The tracing dumps can be quite verbose and for some applications that are constantly running you run the risk of overloading the machine and the hard drive there. Five levels range from none to Verbose, allowing fine-tuning the tracing activities.

90. Where is the output of TextWriterTraceListener redirected?
To the Console or a text file depending on the parameter passed to the constructor.

91. What is a pre-requisite for connection pooling?
Multiple processes must agree that they will share the same connection, where every parameter is the same, including the security settings.

92.   How to use nullable types in .Net?
Value types can take either their normal values or a null value. Such types are called nullable types.



Int? someID = null;
If(someID.HasVAlue)
{
}


Thanks to GOOGLE.