1)What is a static class ?
Static class is like a non static class, the differences is, static class instance cannot be created. It means you cannot use new keyword to the static class. You can access the member of the static class only.
Example
2)What is static member ?
If an attribute value of a class is same across the all instance, it is called static member. For example, last name student, have variable age, is value is 20 across all instance of the student. This variable is considered as static variable.
Example
3)What is protected internal ?
Protected internal means, a class is derived from a specific base class and it is available to the class within the same assembly.
4)Can you declare an override method static if the original method is not static ?
No, original method and Virtual method must be same signature.
5)Can you implement access modifier to a destructor ?
Destructor cannot have access modifier.
6) what is early and late binding?
At the compile time, calling non Virtual method is called early binding.At the runtime ,calling virtual method is known as late binding. Late binding is decided at runtime, which method to be called at that time.
7)What is boxing?
An implicit conversation, converting value type to reference type , is called boxing.
Example
8)What is conversion type ?
Convert data from one type to another type is called conversion type. For example we are converting integer to string or string to integer with the help of convert to string or convert to int.
Example
9)What is the full form of ajax ?
The full form of ajax Asynchronous JavaScript and XML.
10)Name some inbuilt abstract class in.Net framework.
webresqest and webresponse
11)Does function overloading depend on return type?
No , function overloading means, when functionis define with same name with several arguments. When called by name and argument, the overloading which match exactly with argument , that function is called. The function argument does not depend on return type . If a function is declared with same argument and name with different return type, the compiler will give error.
12)Swap a variable without using third variable.
Example
13)Is it possible, to declare abstract method in a non abstract class?
No, compiler will throw error.
14) What is the way, you should implement to protect your class from inherit ?
The class should be declaere with the access modifiers shield. Seal keyword prevent class inherit further.
Example
15)A child class can inherit constructor of his base class ?
The answer is no, constructor of a class cannot be inherited.
16)What is unboxing?
Unboxing is also conversion process, where value type is converted to objec type.
Example
17)What is queue and what is stack ?
queue : queue means a line some object. You can say, rail wagon are in queue. queue follow fast in and fast out or FIFO method. Object in a queue inserted from one end and deleted from other end.
stack : you can compare stack as dinner plate. The last inserted in dinner plate will be remove fast. Stack insert is known as push operation and delete is known as pop operation.
18) what are the namespace used for Globalisation and localisation ?
System.Globalisation
system.Resources
19)Can we write, overloading of function in a same class ?
no
20)What are the default access modifier of a class ,structure or interface ?
Internal
21) How many level of inheritance,.Net support ?
.Net do not support multiple inheritance..Net class cannot be inherited from more than one class.If you want to multiple inheritance, create multiple interface,.Net class support multiple interface.
Example
22) what is virtual function ?
Virtual function is defined in the base class. Virtual keyword inform the compiler, that this function will be Re define in the child class again .
Example
23)What is execute ExecuteNonQuery ?
It is used during a command execution in the database. A command may be select / insert /update / delete query. ExecuteNonQuery inform the compiler after the command execution there is nothing to return.
Example
24)What is difference between post increment and pre increment ?
Pre increment means, first increment is done then assignment
Example
Post increment means, first assignment is done , after increment is made.
Example
25)Define a class ,where only single instance can be created ?
Using a Keyword singleton and assign it to a variable which is static and readonly , prevent a class to create more than one instance. This technique guaranteed that this class only single instance is created.
Example
26)Is it possible to declare abstract class without abstract method ?
Yes, an abstract class can be declared without any abstract method.
Example
27) can we declare constructor as private?
Yes we can, but declaring a constructor private, the class will lose it inherit functionality and work as a singleton pattern.
Example
28)What is explicit conversion ?
Conversion when implicit conversion is not possible, explicit conversion is done.There is a chance of losing data in this type
of conversion
Example
Value of b =10
Static class is like a non static class, the differences is, static class instance cannot be created. It means you cannot use new keyword to the static class. You can access the member of the static class only.
Example
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
namespace
ConsoleApplication1
{
class
Program
{
static
void
Main(string[]
args)
{
student
obj = new
student();
}
}
}
static
class
student
{
static
string
Name;
static
int
roll;
}
error//Cannot
declare a variable of static type 'student'
If an attribute value of a class is same across the all instance, it is called static member. For example, last name student, have variable age, is value is 20 across all instance of the student. This variable is considered as static variable.
Example
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
namespace
ConsoleApplication1
{
class
Program
{
static
void
Main(string[]
args)
{
Console.WriteLine("roll
:"
+ student.roll.ToString());
Console.ReadKey();
}
}
}
class
student
{
public
static
int
roll=20;
}
Output :
roll :20
3)What is protected internal ?
Protected internal means, a class is derived from a specific base class and it is available to the class within the same assembly.
//Same
Assembly
class
student
{
public
int
roll=20;
}
class
MyClass
: student
{
}
No, original method and Virtual method must be same signature.
5)Can you implement access modifier to a destructor ?
Destructor cannot have access modifier.
6) what is early and late binding?
At the compile time, calling non Virtual method is called early binding.At the runtime ,calling virtual method is known as late binding. Late binding is decided at runtime, which method to be called at that time.
7)What is boxing?
An implicit conversation, converting value type to reference type , is called boxing.
Example
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
namespace
ConsoleApplication1
{
class
Program
{
static
void
Main(string[]
args)
{
int
i = 123;
object
obj = i;
Console.ReadKey();
}
}
}
8)What is conversion type ?
Convert data from one type to another type is called conversion type. For example we are converting integer to string or string to integer with the help of convert to string or convert to int.
Example
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
namespace
ConsoleApplication1
{
class
Program
{
static
void
Main(string[]
args)
{
int
i = 123;
String
s = Convert.ToString(i);
Console.ReadKey();
}
}
}
9)What is the full form of ajax ?
The full form of ajax Asynchronous JavaScript and XML.
10)Name some inbuilt abstract class in.Net framework.
webresqest and webresponse
11)Does function overloading depend on return type?
No , function overloading means, when functionis define with same name with several arguments. When called by name and argument, the overloading which match exactly with argument , that function is called. The function argument does not depend on return type . If a function is declared with same argument and name with different return type, the compiler will give error.
class
student
{
private
int
Method1(int
a,int
b)
{
return
0;
}
private
string
Method1(int
a, int
b)
{
return
"0";
}
}
Error
:'student'
already defines a member called 'Method1'
with the same parameter types.
12)Swap a variable without using third variable.
Example
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
namespace
ConsoleApplication1
{
class
Program
{
static
void
Main(string[]
args)
{
int
a = 50;
int
b = 70;
a
= a + b;
b
= a - b;
a
= a - b;
Console.WriteLine("a="
+ a.ToString());
Console.WriteLine("b="
+ b.ToString());
Console.ReadKey();
}
}
}
Output
:
a=70
b=50
13)Is it possible, to declare abstract method in a non abstract class?
No, compiler will throw error.
14) What is the way, you should implement to protect your class from inherit ?
The class should be declaere with the access modifiers shield. Seal keyword prevent class inherit further.
Example
sealed
class student
{
private
student()
{
}
}
class
MyClass
: student
{
}
error
: 'MyClass':
cannot derive from sealed
type 'student'
The answer is no, constructor of a class cannot be inherited.
16)What is unboxing?
Unboxing is also conversion process, where value type is converted to objec type.
Example
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
namespace
ConsoleApplication1
{
class
Program
{
static
void
Main(string[]
args)
{
object
obj = 123;
int
i = (int)obj;
Console.WriteLine("i="
+ i.ToString());
Console.ReadKey();
}
}
}
Output
i=123
17)What is queue and what is stack ?
queue : queue means a line some object. You can say, rail wagon are in queue. queue follow fast in and fast out or FIFO method. Object in a queue inserted from one end and deleted from other end.
stack : you can compare stack as dinner plate. The last inserted in dinner plate will be remove fast. Stack insert is known as push operation and delete is known as pop operation.
18) what are the namespace used for Globalisation and localisation ?
System.Globalisation
system.Resources
19)Can we write, overloading of function in a same class ?
no
20)What are the default access modifier of a class ,structure or interface ?
Internal
21) How many level of inheritance,.Net support ?
.Net do not support multiple inheritance..Net class cannot be inherited from more than one class.If you want to multiple inheritance, create multiple interface,.Net class support multiple interface.
Example
//Single
level inherihance
class
student1
{
public
string
name;
}
class
MyClass
: student1
{
public
void
Method1()
{
}
}
//Multiple
inherihance
class
student1
{
public
string
name;
}
class
student2
{
public
string
name;
}
class
MyClass
: student1,
student2
{
public
void
Method1()
{
}
}
Error
:Class 'MyClass'
cannot have multiple base
classes: 'student1'
and 'student2'
22) what is virtual function ?
Virtual function is defined in the base class. Virtual keyword inform the compiler, that this function will be Re define in the child class again .
Example
class
student
{
public
virtual
Method1()
{
}
}
class
MyClass
: student
{
public
void
Method1()
{
}
}
23)What is execute ExecuteNonQuery ?
It is used during a command execution in the database. A command may be select / insert /update / delete query. ExecuteNonQuery inform the compiler after the command execution there is nothing to return.
Example
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.Data.SqlClient;
namespace
ConsoleApplication1
{
class
Program
{
static
void
Main(string[]
args)
{
SqlConnection
con=new
SqlConnection("Your
Conncetion String");
SqlCommand
scmd=new
SqlCommand("Your
Query",con);
scmd.EndExecuteNonQuery();
Console.ReadKey();
}
}
}
24)What is difference between post increment and pre increment ?
Pre increment means, first increment is done then assignment
Example
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
namespace
ConsoleApplication1
{
class
Program
{
static
void
Main(string[]
args)
{
int
i = 5;
int
a = ++i;
Console.WriteLine("a="
+ a.ToString());
Console.ReadKey();
}
}
}
Post increment means, first assignment is done , after increment is made.
Example
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
namespace
ConsoleApplication1
{
class
Program
{
static
void
Main(string[]
args)
{
int
i = 5;
int
a = i++;
Console.WriteLine("a="
+ a.ToString());
Console.ReadKey();
}
}
}
25)Define a class ,where only single instance can be created ?
Using a Keyword singleton and assign it to a variable which is static and readonly , prevent a class to create more than one instance. This technique guaranteed that this class only single instance is created.
Example
public
sealed
class
student
{
private
static
readonly
student
instance = new
student();
static
student()
{
}
private
student()
{
}
public
static
student
Instance
{
get
{
return
instance;
}
}
}
26)Is it possible to declare abstract class without abstract method ?
Yes, an abstract class can be declared without any abstract method.
Example
abstract
class
student
{
public
int
roll=20;
public
virtual
void
Method1()
{
}
}
class
MyClass
: student
{
public
void
Method1()
{
}
}
Compiler does not show any error
27) can we declare constructor as private?
Yes we can, but declaring a constructor private, the class will lose it inherit functionality and work as a singleton pattern.
Example
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
namespace
ConsoleApplication1
{
class
Program
{
static
void
Main(string[]
args)
{
student
obj = new
student();
Console.ReadKey();
}
}
}
class
student
{
private
student()
{
}
}
Error
:'student.student()'
is
inaccessible due to its protection level
28)What is explicit conversion ?
Conversion when implicit conversion is not possible, explicit conversion is done.There is a chance of losing data in this type
of conversion
Example
namespace
ConsoleApplication1
{
class
Program
{
static
void
Main(string[]
args)
{
double
a=10.75;
int
b;
b=(int)a;
Console.WriteLine("Value
of b ="
+ b.ToString());
Console.ReadKey();
}
}
}
Output:Value of b =10
No comments:
Post a Comment