OOPS Interview Questions and Answers (133) - Page 3

What is Early binding and late binding?

Calling a non-virtual method, decided at a compile time is known as early binding. Calling a virtual method (Pure Polymorphism), decided at a runtime is known as late binding.
Difference between ASP Session and ASP.NET Session?

Asp.net session supports cookie less session & it can span across multiple servers.
Illustrate Server.Transfer and Response.Redirect?

Server.Transfer, transfers the control of a web page, posting a form data, while Response.Redirect simply redirects a page to another page, it can not post a form data to another page. Server.Transfer is more efficient over the Response.Redirect, because Response.Redirect causes a round trip to server as the page is processed once again on the client and a request is made to server there after.
But the browser url is not changed in case of Server.Transfer i.e. Browser history is not modified in using it.
How's method overriding different from overloading?

When overriding, you change the method behavior for a derived class. Overloading simply involves having a method with the same name within the class.
Can you declare the override method static while the original method is non-static?

No, you can't, the signature of the virtual method must remain the same, only the keyword virtual is changed to keyword override.
Can you override private virtual methods?

No, you cannot access private methods in inherited classes.
Can you prevent your class from being inherited and becoming a base class for some other classes?

Yes, that's what keyword sealed in the class definition is for. The developer trying to derive from your class will get a message: cannot inherit from Sealed class WhateverBaseClassName. It's the same concept as final class in Java.
Can you allow class to be inherited, but prevent the method from being over-ridden?

Yes, just leave the class public and make the method sealed.
Why can't you specify the accessibility modifier for methods inside the interface?

you are not allowed to specify any accessibility, it's public by default.
Static datamembers should be initialized inside the constructor. True or False.

False. Static datamembers should not be initialised inside constructor.
A constructor can be private. True or False

True. A constructor can be private. We can declare a constructor as private.
What is the work of a constructor?

Constructor creates and initialises the objects in an application.
What is "this" pointer?

This pointer is a pointer which points to the current object of a class. this is actually a keyword which is used as a pointer which differentiate the current object with global object.
Difference between sealed and static classes

sealed classes:

1)we can create their instances, but cannot inherit them

ex:

sealed class demo
{

}

class abc:demo
{
--Wrong
}
2)They can contain static as well as nonstatic members.

static classes:

1)we can neither create their instances, nor inherit them

ex:
static class Program
{

}

2)They can have static members only.
Differences between a structure and class

Structure:

1)It is a Value Type
2)Its variable directly contains the data on the stack
3)Each structure variable has its independent copy
of data.
4)One structure cannot inherit other
5)They do not have destructors
6)They do no have explicit parameterless constructors
7)we cannot put sealed /abstract modifiers before the structures.
8)Easier memory management
9)examples:
int, short,long,DateTime,
Point
(predefined)

Uses:
Structures are typically used for handling
small amounts of data or where inheritance, overriding is not required
example: int a=100;


Class

1)It is a reference Type
2)Its variable has references to the data(data is stored in the object created in the heap) .
3)Two Class variables can refer to the same object
4)One class can inherit the other(unless the class is sealed/static)
5)Classes have destructors
6)They can have explicit parameterless constructors
7)Sealed/abstract modifers can be put before classes.
8) Comparitively Difficult memory management
9)example: SqlConnection,DataView(predefined classes)

Classes are typically used where inheritance, overriding is required
or we need to create objects capable of handling large data
example: DataSet,ArrayList can handle large data.
Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Interview Questions and Answers Categories