Interview Questions  

Go Back   Interview Questions > Interview Questions & Answers > Information Technology > Microsoft Technologies > Dot Net > ASP.NET

ASP.NET ASP.NET Interview Questions, Learn by sharing ASP.NET Interview Questions asked in various companies, Get Career advices, Interview Procedures from ASP.NET experts, Post asked ASP.NET Interview Questions and Answers.

   

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-13-2008, 10:02 AM
Senior Member
 
Join Date: Feb 2008
Posts: 9,095
Default What is shadowing?

What is shadowing?
Reply With Quote
  #2 (permalink)  
Old 05-16-2008, 12:43 PM
Junior Member
 
Join Date: May 2008
Posts: 6
Thumbs up

super class defenition can refer subclass object.

using system;
public class class1
{
public void hello1()
{
console.writeline("super class");
}
}
public class class2:class1
{
Public void hello2()
{
console.writeline("subclass");
}
}
public class mainclass
{
static void main()
{
class1 c1=new class2(); //method shadowing
c1.hello1();
}
}
Reply With Quote
  #3 (permalink)  
Old 06-07-2008, 09:52 AM
Junior Member
 
Join Date: Jun 2008
Posts: 27
Default

shadowing that redefines the function in derived class which has same in base clss
Reply With Quote
  #4 (permalink)  
Old 06-09-2008, 06:08 AM
Junior Member
 
Join Date: Jun 2008
Posts: 1
Default Shadowing

Shadowing is a concept seen when inheritance is brought into effect.

When you have a base class and a derived class, inheritance inherits all the exposed functionalities of the base class to the derived class. This means now you can implement all the public or protected functions or methods in the derived class to extend the functionality of the base function. Alternatively, if we shadow a function in the derived class, we has the function with the same name as with the base class but shadowed method cannot be accessed from the object of the base class. Whereas overridden method in the derived class can be accessed from the object of the base class. To access an shadowed method, you have to create object of the derived class and it cannot be accessed through the base class object.

Let me give you an example:

Class Math
{
virtual sub Add(int a, int b);
}

Class MathExt
{
overrides sub Add(int a, int b){....};
shadows sub Add(double a, int b){.....};

}

Main
{
Math m1 = new Math();
MathExt me1 = new MathExt();
int a;
int b;
float c;
m1.Add(a,b)----> this call ultimately lands in the derived class calling the function with same signature and overrides keyword.

m1.Add(c,b)----> this gives an error as base and its derived class has no overridden function of the same signature

me1.Add(c.b)---> works
}
Reply With Quote
Reply

Tags
asp.net, interview questions

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On