C# .NET - oops concept - Asked By gnanam gnanam on 02-Aug-08 01:53 AM

1.What is use of function overloading?

2.What is main difference between function overloading and overriding?

3.what is output of this coding?

    public class first

{

public void display()

{

Response.write("Base class");

}

}

public class second:first

{

public void display()

{

response.write("derived class");
}

}

main

second  obj = new second();

obj.display()


what is output of this?


5.what is use of css?

6.why should use the class?what are the benifit of class?


c# function - ajay choudhary replied to gnanam gnanam on 02-Aug-08 02:09 AM

What is use of function overloading?
   € : a funtion have same name but different parameter
  ex.    display(int UserID)
             {
                    ---
                 }
        dispaly(int UserID,string UserName)
         {------
        }
3.what is output of this coding?
       € : derived class
5.what is use of css?
   € : using the web application we  are using the css file for design perpuse
6 .why should use the class?what are the benifit of class?
       its a collection of data member and member function.


reply - Binny ch replied to gnanam gnanam on 02-Aug-08 02:36 AM

    Ex of function ocerloading
using System;
class Overload
{
static void Main() {
myFunc();
myFunc( 1);
}
static void myFunc() {
Console.WriteLine("I got no parameters");
}
static void myFunc( int n) {
Console.WriteLine( "I got the number {0}", n);
}
}

http://fox.wikis.com/wc.dll?Wiki~FunctionOverloadingInCSharp~VFP
Metoh override eample
using System;
using System.Diagnostics;
using System.IO;
public class ClassA {
public virtual void MethodA() {
Trace.WriteLine("BaseClass MethodA");
}
}

public class ClassB :ClassA{
public override void MethodA() {
Trace.WriteLine("SubClass MethodA overridden");
}
}

//implementation class for using the above defined classes
public class TopLevel {
static void Main(string[] args) {
TextWriter tw = Console.Out;
Trace.Listeners.Add(new TextWriterTraceListener(tw));

ClassA obj = new ClassB();
obj.MethodA(); // Output will be “Subclass MethodA overridden”
}
}
http://www.dotnetspider.com/resources/468-How-function-overriding-works-C-what-sh.aspx
Hope it helps


Oops Concepts - Shailendrasinh Parmar replied to gnanam gnanam on 02-Aug-08 02:39 AM


Function Overloading


In order to overload a function, a different signature should be used for each overloaded version. A function signature consists of the list of types of its arguments as well as their order. Here's a set of valid overloaded versions of a function named f:

 
void f(char c, int i);
void f(int i, char c);
void f(string & s);
void f();
void f(int i);
void f(char c);

Note, however, that a function differing only by return type is illegal (it is legal to use different a return type with a different argument list, though) :

 
int f();  //error; differs from void f(); above only by return type
int f(float f);  //fine. unique signature


Difference betweein Function Overloading and overriding

The main difference between overloading and overriding is
that in overloading we can use same function name with
different parameters for multiple times for different tasks
with on a class.
and overriding means we can use same name fiunction name
with same parameters of the base class in the derived class.
this is also called as reusability of code in the programme.


To know why to use CSS read these articles ::


http://www.westciv.com/style_master/academy/css_tutorial/introduction/key_ideas.html

http://www.irt.org/articles/js135/

Hope it helps.

OOPS - Kalit Sikka replied to gnanam gnanam on 02-Aug-08 02:40 AM

1.What is use of function overloading?

In programming, using the same name for two or more functions. The compiler determines which function to use based on the type of function, arguments passed to it and type of values returned.

2.What is main difference between function overloading and overriding?

Function Overloading is the implementation of static polymorphism where same function name having different defenitions for different uses. 
 
Function overriding is applicable for dynamic polymorphism where where the function name and the definition are same but the function call is decided at the run time according to the type of object reference

3.what is output of this coding?

    public class first

{

public void display()

{

Response.write("Base class");

}

}

public class second:first

{

public void display()

{

response.write("derived class");
}

}

main

second  obj = new second();

obj.display()


what is output of this?

Output: derived class

Because Here it has override method define in baseclass

5.what is use of css?

A method used to attach styles such as specific fonts, colors, and spacing to HTML documents. Because they "cascade," some elements take precedence over others.

6.why should use the class?what are the benifit of class?

A class is an organized store-house in object-oriented programming that gives coherent functional abilities to a group of related code. It is the definition of an object, made up of software code. Using classes, we may wrap data and behaviour together (Encapsulation). We may define classes in terms of classes (Inheritance). We can also override the behaviour of a class using an alternate behaviour (Polymorphism).

Oops Concepts - Sagar P replied to gnanam gnanam on 02-Aug-08 03:16 AM
Function overloading is the practice of declaring the same function with different signatures. The same function name will be used with different number of parameters and parameters of different type. But overloading of functions with different return types are not allowed.

http://www.codersource.net/cpp_tutorial_function_overloading.html# with the integer data, other can deal float for precision etc.,

Overriding :Directs PB to deviate from its normal execution sequence. Both functions and events can be overridden.

Function Overriding : A descendant function has the same function signature as an ancestor function. The descendant function is executed instead of the ancestor function.

Event overriding : A descendant has the Override Ancestor Script option checked.

Go thr this links to know more abt Overriding;

http://www.codeproject.com/KB/mcpp/cppclioverriding.aspx

http://www.c-sharpcorner.com/UploadFile/cupadhyay/FunctionOverridingandItsImpact11292005060858AM/FunctionOverridingandItsImpact.aspx

Diff bet Both;

Method overriding is when a child class redefines the same method as a parent class, with the same parameters.
For example, the standard Java class java.util.LinkedHashSet extends java.util.HashSet. The method add() is overridden in LinkedHashSet. If you have a variable that is of type HashSet, and you call its add() method, it will call the appropriate implementation of add(), based on whether it is a HashSet or a LinkedHashSet. This is called polymorphism.

Method overloading is defining several methods in the same class, that accept different numbers and types of parameters. In this case, the actual method called is decided at compile-time, based on the number and types of arguments. For instance, the method System.out.println() is overloaded, so that you can pass ints as well as Strings, and it will call a different version of the method.

OUTPUT : derived class

as the object is of derived class it will call the function of derived.

CSS:

As a developer this means that the information in your web site should go into your HTML files, but HTML files should not contain information about how that information is displayed. And you've probably guessed by now that information about how the pages should appear goes into CSS files.

You might wonder what advantages this conveys. Why go to all of this trouble? Just a couple of advantages might give you an idea about why this approach has long been considered beneficial in areas of document management that have been around a lot longer than the world wide web.

The traditional HTML approach was to "hardcode" all of the appearance information about a page. So you want all your headings in courier, and at different point sizes to the sizes built into browsers? Then, for every heading, in every page, set the font size and face properties. You've got more than 100 pages? That is a lot of editing, and a lot of re-editing if you decide to modify the appearance of your pages later. And with all of that editing there is plenty of possibility for introducing errors.

With CSS, you can decide how headings should appear, and enter that information once. Every heading in every page that is linked to this style sheet now has that appearance. Want to make every heading of level 3 more obviously different from those of level 2? Edit the style sheet, and every such heading now has the altered appearance. How many hours' work (and potential errors) have you just saved?

Another major advantage involves the management of large, sophisticated sites. With cascading style sheets, whole organizations can share a small number of style sheets, ensuring consistency across the site with no need for constant updating and editing to accommodate changes. For a discussion of this advantage in detail, see http://www.westciv.com/style_master/academy/css_tutorial/advanced/cascade_inheritance.html#large sites, in the section on cascade and inheritance.

There are plenty of other advantages, too. We return to this issue in more detail in the http://www.westciv.com/style_master/academy/css_tutorial/real_world/index.html section of the guide. For now though, let's find out what a style sheet actually is and how it performs all these miracles.

http://www.w3schools.com/css/

http://www.echoecho.com/css.htm

CLASS:

In the real world, you'll often find many individual objects all of the same kind. There may be thousands of other bicycles in existence, all of the same make and model. Each bicycle was built from the same set of blueprints and therefore contains the same components. In object-oriented terms, we say that your bicycle is an instance of the class of objects known as bicycles. A class is the blueprint from which individual objects are created.

There are many Adavantages of Class;

You can have resuability of all the methods n properties.
You can acheive Polymorohism, Inheritance, Encapsulation with class.
You can speed u application usig class.
You can save memory. 

Best Luck!!!!!!!!!!!!!!!!!
Sujit.