Custom Search
/* text ----------------------------------------------- */ #header h1 { color: #feeef3; font: normal bold 200% Helvetica,Arial,Verdana,'Trebuchet MS', Sans-serif; } #header .description { margin: 0; padding-top: 7px; padding-right: 16px; padding-bottom: 0; padding-left: 84px; color: #feeef3; font: normal normal 80% Helvetica,Arial,Verdana,'Trebuchet MS', Sans-serif; } .post-body p { line-height: 1.4em; /* Fix bug in IE5/Win with italics in posts */ margin: 0; height: 1%; overflow: visible; } .post-footer { font-size: 80%; color: #c88fa2; } .uncustomized-post-template .post-footer { text-align: right; } .uncustomized-post-template .post-footer .post-author, .uncustomized-post-template .post-footer .post-timestamp { display: block; float: left; text-align: left; margin-right: 4px; } p.comment-author { font-size: 83%; } .deleted-comment { font-style:italic; color:gray; } .comment-body p { line-height: 1.4em; } .feed-links { clear: both; line-height: 2.5em; margin-bottom: 0.5em; margin-left: 29px; } #footer .widget { margin: 0; padding-top: 0; padding-right: 0; padding-bottom: 15px; padding-left: 55px; color: #feeef3; font-size: 90%; line-height: 1.4em; background: url(http://www.blogblog.com/thisaway_rose/icon_footer.gif) no-repeat 16px 0; } /* lists ----------------------------------------------- */ .post ul { padding-left: 32px; list-style-type: none; line-height: 1.4em; } .post li { padding-top: 0; padding-right: 0; padding-bottom: 4px; padding-left: 17px; background: url(http://www.blogblog.com/thisaway_rose/icon_list_item_left.gif) no-repeat left 3px; } #comments ul { margin: 0; padding: 0; list-style-type: none; } #comments li { padding-top: 0; padding-right: 0; padding-bottom: 1px; padding-left: 17px; background: url(http://www.blogblog.com/thisaway_rose/icon_comment.gif) no-repeat left 3px; } .sidebar ul { padding: 0; list-style-type: none; line-height: 1.2em; margin-left: 0; } .sidebar li { padding-top: 0; padding-right: 0; padding-bottom: 4px; padding-left: 17px; background: url(http://www.blogblog.com/thisaway_rose/icon_list_item.gif) no-repeat left 3px; } #blog-pager-newer-link { float: left; margin-left: 29px; } #blog-pager-older-link { float: right; margin-right: 16px; } #blog-pager { text-align: center; } /* links ----------------------------------------------- */ a { color: #bf277e; font-weight: bold; } a:hover { color: #96095a; } a.comment-link { /* ie5.0/win doesn't apply padding to inline elements, so we hide these two declarations from it */ background/* */:/**/url(http://www.blogblog.com/thisaway_rose/icon_comment.gif) no-repeat left 45%; padding-left: 14px; } html>body a.comment-link { /* respecified, for ie5/mac's benefit */ background: url(http://www.blogblog.com/thisaway_rose/icon_comment.gif) no-repeat left 45%; padding-left: 14px; } .sidebar a { color: #e25984; } .sidebar a:hover { color: #b02c56; } #header h1 a { color: #feeef3; text-decoration: none; } #header h1 a:hover { color: #d9b4c1; } .post h3 a { text-decoration: none; } a img { border-width: 0; } .clear { clear: both; line-height: 0; height: 0; } .profile-textblock { clear: both; margin-bottom: 10px; margin-left: 0; } .profile-img { float: left; margin-top: 0; margin-right: 5px; margin-bottom: 5px; margin-left: 0; padding: 3px; border: 1px solid #ebbdcc; } .profile-link { padding-top: 0; padding-right: 0; padding-bottom: 0; padding-left: 17px; background: url(http://www.blogblog.com/thisaway_rose/icon_profile_left.gif) no-repeat left 0; } /** Page structure tweaks for layout editor wireframe */ body#layout #main, body#layout #sidebar { padding: 0; } -->

Saturday, January 10, 2009

Object Oriented Concepts for Interview

Inheritance

Visual Basic .NET supports inheritance by allowing you to define classes that serve as the basis for derived classes. Derived classes inherit and can extend the properties and methods of the base class. They can also override inherited methods with new implementations. All classes created with Visual Basic .NET are inheritable by default. Because the forms you design are really classes, you can use inheritance to define new forms based on existing ones.

Overloading

Overloading is the ability to define properties, methods, or procedures that have the same name but use different data types. Overloaded procedures allow you to provide as many implementations as necessary to handle different kinds of data, while giving the appearance of a single, versatile procedure.

Overriding Properties and Methods

The Overrides keyword allows derived objects to override characteristics inherited from parent objects. Overridden members have the same arguments as the members inherited from the base class, but different implementations. A member's new implementation can call the original implementation in the parent class by preceding the member name with MyBase.

Constructors and Destructors

Constructors are procedures that control initialization of new instances of a class. Conversely, destructors are methods that free system resources when a class leaves scope or is set to Nothing. Visual Basic .NET supports constructors and destructors using the Sub New and Sub Finalize procedures.

Class Modifiers

 

There are seven different - optional - class modifiers. Four of these - 'public', 'internal', 'protected' and 'private' - are used to specify the access levels of the types defined by the classes. The following five different access levels can be specified with these four modifiers:

 

     Public

The 'public' keyword identifies a type as fully accessible to all other types. This is the implicit accessibility of enumeration members (lesson 7) and interface members (lesson 11).

 

    Internal

If a class is declared as 'internal', the type it defines is accessible only to types within the same assembly (a self-contained 'unit of packaging' containing code, metadata etc.). This is the default access level of non-nested classes.

 

     Protected

If a class is declared as 'protected', its type is accessible by a containing type and any type that inherits from this containing type. This modifier should only be used for internal classes (ie. classes declared within other classes).

 

     Protected internal

 

The permissions allowed by this access level are those allowed by the 'protected' level plus those allowed by the 'internal' level. The access level is thus more liberal than its parts taken individually. This modifier should only be used for internal classes (ie. classes declared within other classes).

 

       Private

 

Where a class is declared as 'private', access to the type it defines is limited to a containing type only. This modifier should only be used for internal classes (ie. classes declared within other classes).

 

We now turn to the final three class modifiers:

 

     New

 

The 'new' keyword can be used for 'nested' classes. A nested class is one that is defined in the body of another class; it is in most ways identical to a class defined in the normal way, but its access level cannot be more liberal than that of the class in which it is defined. A nested class should be declared using the 'new' keyword just in case it has the same name as (and thus overrides) an inherited type.

 

      Abstract

 

A class declared as 'abstract' cannot it be instanced - it is designed only to be a base class for inheritance.

 

      Sealed

 

A class declared as 'sealed' cannot be inherited from.

 

Method Modifiers

 

There are ten method modifiers that can be used. Four of these are the access modifiers that can be used in class declarations (see lesson 12). These four work analogously to the way they work in class declarations. The others are the following:

 

    Abstract

Abstract methods are discussed in lesson 11

 

    Static

The 'static' modifier declares a method to be a class method.

The methods (as well as the enumerations, properties and variables) specified in a class can be associated either with the class's instances (i.e. the reference types it specifies) or with the class itself. These methods are called, respectively, 'instance methods' and 'class methods'. Class methods, declared with the 'static' modifier, can be called even when there exists no current instances of the class.

 

There is no equivalent modifier for instance methods, since methods are instance methods just in case their declaration does not include the word 'static'.

 

new, virtual, override

 

     Extern

 

Methods which are given as 'extern' are defined externally, using a language other than C#. We shall not go into the process involved in defining such methods.

 

 

 

 

 

Parameter Passing

 

Passing by value

 

The parameter modifiers 'ref' and 'out' relate to how the parameter is passed into the method. Where neither of these modifiers is used, the parameter is passed in 'by value'. In this case, when the method is called the value given is copied to the variable specified in the method declaration. The following example illustrates this point; note that the change made to variable b in the body of the 'change' method doesn't result in a change to the variable a used to invoke the method.

 

public static void Main ()

{

     int a = 0;

     change (a); // following this method invocation, a equals 0

}

  public static void change (int b)

{

.

     b = 5;

}

 

In this example, it was a value type that was passed 'by value'. But reference types can also be passed 'by value'. As we saw previously, the immediate value held by a reference type variable is actually a memory address. So when this variable is passed 'by value', the memory address is copied to the variable specified in the method head. But of course, because the two variables will hold the same memory address, any changes made within the method body to the object located at that memory address will be reflected outside the method (although this doesn't apply for immutable reference types like strings, which act more like value types - see lesson 4).

 

Passing by reference

 

In C# we can pass variables into methods 'by reference'. Where a variable is passed by reference, the 'ref' modifier must be used both in the method head and the method invocation (illustrated by the next code block).

 

Passing by reference is most obviously useful in cases where we want to treat a value type like a reference type. For instance, the method call in the following code does change the value of the variable a passed into the 'change' method.

 

public static void Main ()

{

     int a = 0;

     change (ref a); // following this method invocation, a==5

}

public static void change (ref int b)

{

     b = 5;

 }

 Exception Handling

Visual Basic .NET supports structured exception handling, using an enhanced version of the Try...Catch...Finally syntax supported by other languages such as C++.

Structured exception handling combines a modern control structure (similar to Select Case or While) with exceptions, protected blocks of code, and filters. Structured exception handling makes it easy to create and maintain programs with robust, comprehensive error handlers.

Interfaces

Interfaces describe the properties and methods of classes, but unlike classes, do not provide implementations. The Interface statement allows you to declare interfaces, while the Implements statement lets you write code that puts the items described in the interface into practice.

Delegates

Delegates objects that can call the methods of objects on your behalf are sometimes described as type-safe, object-oriented function pointers. You can use delegates to let procedures specify an event handler method that runs when an event occurs. You can also use delegates with multithreaded applications. For details, see Delegates and the AddressOf Operator.

Shared Members

Shared members are properties, procedures, and fields that are shared by all instances of a class. Shared data members are useful when multiple objects need to use information that is common to all. Shared class methods can be used without first creating an object from a class.

References

References allow you to use objects defined in other assemblies. In Visual Basic .NET, references point to assemblies instead of type libraries. For details, see References and the Imports Statement. Namespaces prevent naming conflicts by organizing classes, interfaces, and methods into hierarchies.

Assemblies

Assemblies replace and extend the capabilities of type libraries by, describing all the required files for a particular component or application. An assembly can contain one or more namespaces.


<%@ page import="java.io.BufferedReader,
java.io.InputStreamReader,
java.io.IOException,
java.io.UnsupportedEncodingException,
java.net.URL,
java.net.URLEncoder" %>
<%!

private static final String PAGEAD =
"http://pagead2.googlesyndication.com/pagead/ads?";

private void googleAppendUrl(StringBuilder url, String param, String value)
throws UnsupportedEncodingException {
if (value != null) {
String encodedValue = URLEncoder.encode(value, "UTF-8");
url.append("&").append(param).append("=").append(encodedValue);
}
}

private void googleAppendColor(StringBuilder url, String param,
String value, long random) {
String[] colorArray = value.split(",");
url.append("&").append(param).append("=").append(
colorArray[(int)(random % colorArray.length)]);
}

private void googleAppendScreenRes(StringBuilder url, String uaPixels,
String xUpDevcapScreenpixels) {
String screenRes = uaPixels;
String delimiter = "x";
if (uaPixels == null) {
screenRes = xUpDevcapScreenpixels;
delimiter = ",";
}
if (screenRes != null) {
String[] resArray = screenRes.split(delimiter);
if (resArray.length == 2) {
url.append("&u_w=").append(resArray[0]);
url.append("&u_h=").append(resArray[1]);
}
}
}

private void googleAppendDcmguid(StringBuilder url, String dcmguid) {
if (dcmguid != null) {
url.append("&dcmguid=").append(dcmguid);
}
}

%>
<%

long googleDt = System.currentTimeMillis();
String googleHost = (request.isSecure() ? "https://" : "http://")
+ request.getHeader("Host");

StringBuilder googleAdUrlStr = new StringBuilder(PAGEAD);
googleAdUrlStr.append("ad_type=text_image");
googleAdUrlStr.append("&channel=");
googleAdUrlStr.append("&client=ca-mb-pub-9201668106503040");
googleAdUrlStr.append("&dt=").append(googleDt);
googleAdUrlStr.append("&format=mobile_single");
googleAppendUrl(googleAdUrlStr, "host", googleHost);
googleAppendUrl(googleAdUrlStr, "ip", request.getRemoteAddr());
googleAdUrlStr.append("&markup=xhtml");
googleAdUrlStr.append("&oe=utf8");
googleAdUrlStr.append("&output=xhtml");
googleAppendUrl(googleAdUrlStr, "ref", request.getHeader("Referer"));
String googleUrl = request.getRequestURL().toString();
if (request.getQueryString() != null) {
googleUrl += "?" + request.getQueryString().toString();
}
googleAppendUrl(googleAdUrlStr, "url", googleUrl);
googleAppendUrl(googleAdUrlStr, "useragent", request.getHeader("User-Agent"));
googleAppendScreenRes(googleAdUrlStr, request.getHeader("UA-pixels"),
request.getHeader("x-up-devcap-screenpixels"));
googleAppendDcmguid(googleAdUrlStr, request.getHeader("X-DCMGUID"));

try {
URL googleAdUrl = new URL(googleAdUrlStr.toString());
BufferedReader reader = new BufferedReader(
new InputStreamReader(googleAdUrl.openStream(), "UTF-8"));
for (String line; (line = reader.readLine()) != null;) {
out.println(line);
}
} catch (IOException e) {}

%>

No comments:

Post a Comment