To create a derived class in VB.NET, the class declaration should be done as:
Class child
Inherits parent
End Class
Multiple inheritance
Multiple inheritance is the possibility that a child class can have multiple parents.
Human beings have always two parents, so a child will have characteristics from both
parents.
Sealed class
A sealed class is a class that does not allow inheritance. Some object model designs
need to allow the creation of new instances but not inheritance, if this is the case,
the class should be declared as sealed.
To create a sealed class in C#, the class declaration should be done as:
To create a sealed class in VB.NET, the class declaration should be done as:
Abstraction
An abstract class is a parent class that allows inheritance but can never be
instantiated. Abstract classes contain one or more abstract methods that do not have
implementation. Abstract classes allow specialization of inherited classes.
Figure 2 shows a Shape class, which is an abstract class. In the real world, you never
calculate the area or perimeter of a generic shape, you must know what kind of
geometric shape you have because each shape (eg. square, circle, rectangle, etc.)
has its own area and perimeter formulas. The parent class shape forces all derived
classes to define the behavior for CalculateArea() and CalculatePerimeter(). Another
great example is a bank account. People own savings accounts, checking accounts,
credit accounts, investment accounts, but not generic bank accounts. In this case, a
bank account can be an abstract class and all the other specialized bank accounts
inherit from bank account.
To create an abstract class in C#, the class declaration should be done as:
To create an abstract class in VB.NET, the class declaration should be done as:
/// C#
--------------------------------------------------------------------------------
using System;
namespace DotNetTreats.OOSE.OOPSamples{
public abstract class Shape{
private float _area;
private System.Drawing.Color _color;
private float _perimeter;
public float Area{
get{
return _area;
}
set{
_area = value;
}
}
}
}
Polymorphism
Figure 2 shows a Rectangle, a Circle, and Square. All of them are shapes and as
shapes their area and perimeter can be calculated; however, each shape calculates
its area in a specialized way. Declaring a member as abstract allows polymorphism.
The Shape class defines the CalculateArea() and CalculatePerimeter() methods as
abstract, this allows each derived class to override the implementation of the
parent's methods.
/// C#
--------------------------------------------------------------------------------
using System;
namespace DotNetTreats.OOSE.OOPSamples{
class Rectangle : Shape{
private float _height;
private float _width;
public rectangle(float height, float width){
_height = height;
_width = width;
}
public float Height{
get{
return _height;
}
set{
_height = value;
}
}
public float Width{
get{
return _width;
}
set{
_width = value;
}
}
public override void CalculateArea(){
this.Area = _height * _width;
}
public override void CalculatePerimeter(){
this.Perimeter = (_height * 2) + (_width * 2);
}
}
}
Virtual keyword
The virtual keyword allows polymorphism too. A virtual property or method has an
implementation in the base class, and can be overriden in the derived classes.
Override keyword
Conclusion
1. What is ViewState?
ViewState allows the state of objects (serializable) to
be stored in a hidden field on the page. ViewState is
transported to the client and back to the server, and is
not stored on the server or any other external source.
ViewState is used the retain the state of server-side
objects between postabacks.
3. What methods are fired during the page load? Init() - when the pageis instantiated, Load()
- when the page is loaded into server memory,PreRender() - the brief moment before the page
is displayed to the user asHTML, Unload() - when page finishes loading.
4. Where does the Web page belong in the .NET Framework class
hierarchy?System.Web.UI.Page
5. Where do you store the information about the user’s locale? System.Web.UI.Page.Culture
7. What’s a bubbled event? When you have a complex control, like DataGrid, writing an event
processing routine for each object (cell, button, row, etc.) is quite tedious. The controls can
bubble up their eventhandlers, allowing the main DataGrid event handler to take care of its
constituents.
8. Suppose you want a certain ASP.NET function executed on MouseOver overa certain button.
Where do you add an event handler? It’s the Attributesproperty, the Add function inside that
property. So btnSubmit.Attributes.Add("onMouseOver","someClientCode();")
9. What data type does the RangeValidator control support? Integer,String and Date.
10. Explain the differences between Server-side and Client-side code? Server-side code runs
on the server. Client-side code runs in the clients’ browser.
11. What type of code (server or client) is found in a Code-Behind class? Server-side code.
12. Should validation (did the user enter a real date) occur server-side or client-side? Why?
Client-side. This reduces an additional request to the server to validate the users input.
13. What does the "EnableViewState" property do? Why would I want it on or off? It enables
the viewstate on the page. It allows the page to save the users input on a form.
14. What is the difference between Server.Transfer and Response.Redirect? Why would I
choose one over the other? Server.Transfer is used to post a form to another page.
Response.Redirect is used to redirect the user to another page or site.
15. Can you explain the difference between an ADO.NET Dataset and an ADO Recordset?
· A DataSet can represent an entire relational database in memory, complete with tables,
relations, and views.
· A DataSet is designed to work without any continuing connection to the original data source.
· Data in a DataSet is bulk-loaded, rather than being loaded on demand.
· There's no concept of cursor types in a DataSet.
· DataSets have no current record pointer You can use For Each loops to move through the
data.
· You can store many edits in a DataSet, and write them to the original data source in a single
operation.
· Though the DataSet is universal, other objects in ADO.NET come in different versions for
different data sources.
16. Can you give an example of what might be best suited to place in the Application_Start
and Session_Start subroutines? This is where you can set the specific variables for the
Application and Session objects.
17. If I’m developing an application that must accommodate multiple security levels though
secure login and my ASP.NET web application is spanned across three web-servers (using
round-robin load balancing) what would be the best approach to maintain login-in state for the
users? Maintain the login state security through a database.
18. Can you explain what inheritance is and an example of when you might use it? When you
want to inherit (use the functionality of) another class. Base Class Employee. A Manager class
could be derived from the Employee base class.
19. Whats an assembly? Assemblies are the building blocks of the .NET framework. Overview
of assemblies from MSDN
20. Describe the difference between inline and code behind. Inline code written along side the
html in a page. Code-behind is code written in a separate file and referenced by the .aspx
page.
21. Explain what a diffgram is, and a good use for one? The DiffGram is one of the two XML
formats that you can use to render DataSet object contents to XML. For reading database data
to an XML file to be sent to a Web Service.
22. Whats MSIL, and why should my developers need an appreciation of it if at all? MSIL is the
Microsoft Intermediate Language. All .NET compatible languages will get converted to MSIL.
23. Which method do you invoke on the DataAdapter control to load your generated dataset
with data? The .Fill() method
24. Can you edit data in the Repeater control? No, it just reads the information from its data
source
25. Which template must you provide, in order to display data in a Repeater control?
ItemTemplate
26. How can you provide an alternating color scheme in a Repeater control? Use the
AlternatingItemTemplate
27. What property must you set, and what method must you call in your code, in order to bind
the data from some data source to the Repeater control? You must set the DataSource
property and call the DataBind method.
28. What base class do all Web Forms inherit from? The Page class.
29. Name two properties common in every validation control? ControlToValidate property and
Text property.
30. What tags do you need to add within the asp:datagrid tags to bind columns manually? Set
AutoGenerateColumns Property to false on the datagrid tag
31. What tag do you use to add a hyperlink column to the DataGrid?
32. What is the transport protocol you use to call a Web service? SOAP is the preferred
protocol.
33. True or False: A Web service can only be written in .NET? False
34. What does WSDL stand for? (Web Services Description Language)
35. Where on the Internet would you look for Web services? (http://www.uddi.org)
36. Which property on a Combo Box do you set with a column name, prior to setting the
DataSource, to display data in the combo box? DataTextField property
37. Which control would you use if you needed to make sure the values in two different
controls matched? CompareValidator Control
38. True or False: To test a Web service you must create a windows application or Web
application to consume this service? False, the webservice comes with a test page and it
provides HTTP-GET method to test.
39. How many classes can a single .NET DLL contain? It can contain many classes.
1) What is CLS (Common Language Specificaiton)?
It provides the set of specificaiton which has to be adhered by any new
language writer / Compiler writer for .NET Framework. This ensures
Interoperability. For example: Within a ASP.NET application written in C#.NET
language, we can refer to any DLL written in any other language supported by
.NET Framework. As of now .NET Supports around 32 languages.
5) What are the different types of assemblies available and their purpose?
Private, Public/shared and Satellite Assemblies.
11. What are ASP.NET Web Forms? How is this technology different than
what is available though ASP (1.0-3.0)?
ASP.NET webforms are analogous to Windows Forms which are available to
most VB developers. A webform is essentially a core container in a Page. An
empty webform is nothing but a HTML Form tag(control) running at server and
posting form to itself by default, but you could change it to post it to
something else. This is a container, and you could place the web controls, user
controls and HTML Controls in that one and interact with user on a postback
basis.
13. How would you implement inheYou missed the number sequence here).
Inheritance is extending the properites, behaviour, methods to child classes
from super classes. VB.NET and C# provide single inheritance, means the
subclasses can be derived from only one parent unlike C++, where true
multiple inheritance is possible. As an alternate to implement multiple
inheritance, we could do the same to implement interfaces to the parent
classes and implement the same interfaces to derive the child classesritance
using VB.NET/C#?
15. Describe the difference between inline and code behind - which is
best in a
16. loosely coupled solution
5 and 16. (You missed the sequence again). Inline style is mixing the server
side code and client side code (HTML and javascript) on the same page and
run it. Where as codebehind is seperating the server side in a different page
(enabling developers/coders to work) and leaving the client side code to do the
presentation only (so designers would work on it). Inline code would be
simplest way of approach because it doesn't require any pre-compilation. But
it is not good in many ways, i. You mix the presentation and server side code
together so whenever there is a change it would be tough to maintain. ii. The
event processing would be a night mare in inline code. iii. Since the
codebehind needs to be compile in advance, it would be faster unline inline,
which is interpreted per call basis. In a loosely couple situation, code-behind
would be the best way to approach. Because it provides better performance
3) 1. What does the keyword static mean when applied to a class member?
1. It means the method can be called through the class without instantiating
the class.
2. Declare a method called calculate that takes one integer, adds one and
returns the result. Allow this method to be overridden by an inheriting class.
2.
Public virtual int calculate(int value)
{
newValue = value + 1;
return newValue;
}
value++;
return value;
4. You can instantiate a class but you cannot instantiate an interace you can
only offer the functionality of that interface.
5. What are the .Net web authentication options and which one would
generally be used for a secured/public site?
5. None
Windows Authentication –Secured side
IIS Authentication
Forms Authentication – Public Side
7. What is a Singleton?
7. This ensures that a class can only be instantiated once.
4) CTS - The common type system is a rich type system, built into the common
language runtime, that supports the types and operations found in most
programming languages. The common type system supports the complete
implementation of a wide range of programming languages.
3. System.Diagnostics
4. System.Data.Common
5. System.Reflection
6.
Protected - Available only to classes that inherit from our class.
Friend - Available only to code within the project/component.
Protected Friend - Available only to classes that inherit from our class (in any
project) or to code within our project/component. This is a combination of
Protected and Friend.
7. Abstract classes cannot be instantiated they can only be extended. You call
the functionality of the abstract class without having to create an instance of
it.
8.
a) Interfaces don't have implementation and abstract classes can be partially
implemented.
From a practical point of view, interfaces can be implemented in any class and
more than one interface can be implemented in a class, but abstract classes
can only be implemented in the same class hierarchy (subclassing) and only
one abstract class can be implemented in a class.
b) Basically it's an mixture of non-virtual methods and method hiding. That is,
in VB.NET overriding methods never hide while non-overriding methods always
do.
c)
Overloading a method means that you are providing another version of an
existing method that takes different input arguments/parameters. The method
will have the same name as an existing method and may or may not have a
different return type. It must have a different number and/or type of input
parameters. Methods are identified by their name, and number and type of
arguments. This is known as the method's signature. The return value of a
method is not regarded as part of the signature. Overloading can be done
within the same class i.e. you can have several methods defined in one class
that have the same name, but different arguments, or it can be done in a class
related to another by inheritance i.e. the superclass contains one method, and
a subclass provides another version of the method with the same name and
different arguments.
Overriding a method means that you are replacing the method with your own
version. The overriding method must be defined identically to the method
being replaced. Overriding can only be done in inherited classes i.e. the
superclass provides a method and the subclass redefines the method with one
that has exactly the same name and arguments as the superclass version. This
will cause the method to behave differently when it is called by an object of
the subclass, to when it is called by an object of the superclass.
9.
Has application scope...variable only goes out of scope when the application
ends.
code:
10.
The datareader is a forward only, readonly object. It will keep a connection
open as long as it is open. It is a fast way to loop through records.
Encapsulation:
Binding of attributes and behaviors. Hiding the implementation and exposing
the functionality.
Abstraction:
Hiding the complexity. Defining communication interface for the functionality
and hiding rest of the things.
In .Net destructor can not be abstract. Can define Either Finalize / Destructor.
For Destructor access specifiers can not be assigned. It is Private.
Overloading:
Adding a new method with the same name in same/derived class but with
different number/types of parameters. Implements Polymorphism.
Overriding:
When we need to provide different implementation than the provide by base
class, We define the same method with same signatures in the derived class.
Method must be Protected/Protected-Friend/Public for this purpose. (Base
class routine can be called by Mybase.Method, base.Method).
Shadowing:
When the method is defined as Final/sealed in base class and not overridable
and we need to provide different implementation for the same. We define
method with Shadows/new.
Inheritance:
Gives you ability to provide is-a relationship. Acquires attributes and behaviors
from another. When a class acquires attributes and behaviors from another
class. (must not be Final or sealed class in .Net)
Abstract Class:
Instance can not be created. Optionally can have one or more abstract
methods but not necessary. Can provide body to Classes.
Interface:
What a Class must do, But not how-to.
Bridge for the communication when the caller does not know to whom he is
calling.
Describes externally visible behavior of element.
Only Public members which defines the means of the communication with the
outer world. Can-be-Used-As Relationship.
Can not contain data but can declare property. There can be no
implementation. Interface can be derived from another interface.
Polymorphism:
Mean by more than one form. Ability to provide different implementation
based on different no./type of parameters. A method behaves differently based
on the different input parameters. Does not depend on the Return-Type.
Pure-Polymorphism:
Make an method abstract/virtual in base class. Override it in Derived Class.
Declare a variable of type base class and assign an object of derived class to
it. Now call the virtual/abstract method. The actual method to be called is
decided at runtime.
Early-Binding:
Calling an non-virtual method decides the method to call at compile time is
known as Early-Binding.
Late-Binding:
Same as pure-polymorphism.
What is a Delegate?
A strongly typed function pointer. A delegate object encapsulates a reference
to a method. When actual function needs to be called will be decided at run-
time.
Constructor:
Special Method Always called whenever an instance of the class is created.
Destructor/Finalize:
Called by GC just before object is being reclaimed by GC.
ASP.Net
Different Types of Caching?
Output Caching: stores the responses from an asp.net page.
Fragment Caching: Only caches/stores the portion of page (User Control)
Data Caching: is Programmatic way to Cache objects for performance.
Role of Global.asax:
Optional file contains the code to handle Application level events raised by
ASP.Net or By HttpModule. This file resides in application root directory.
Application_Start, _End, _AuthenticateRequest, _Error, Session_Start, _End,
BeginRequest, EndRequest. This file is parsed and compiled into dynamically
generated class derived from HttpApplication.
How do you turn off cookies in one page of your asp.net application?
We will not use it. But can not turn off cookies from server. To allow or not is a
client side functionality.