Hi All,
Can u please explain this.
Base Obj = new Derived(); [Base being the base class and Derived being
the derived the class]
Can Obj access methods both of Base and Derived or what will be the
behaviour?
What will be the behaviour for Overridden Methods?
Cheers,
Akhil 4 4346
Obj only can access methods of base(the Interface of Base ),but the behaviour
of method depend on the Derived(for the Overridden Methods or New
Methods,of couse the behaviour of the other method of Derived is same to
the Base)
hope it helps
"Akhil" wrote: Hi All,
Can u please explain this.
Base Obj = new Derived(); [Base being the base class and Derived being the derived the class]
Can Obj access methods both of Base and Derived or what will be the behaviour? What will be the behaviour for Overridden Methods?
Cheers, Akhil
Thanks, But Not Clear though.
--
Cheers,
Akhil
"googou" <go****@discuss ions.microsoft. com> wrote in message
news:D4******** *************** ***********@mic rosoft.com... Obj only can access methods of base(the Interface of Base ),but the
behaviour of method depend on the Derived(for the Overridden Methods or New Methods,of couse the behaviour of the other method of Derived is same
to the Base)
hope it helps
"Akhil" wrote:
Hi All,
Can u please explain this.
Base Obj = new Derived(); [Base being the base class and Derived
being the derived the class]
Can Obj access methods both of Base and Derived or what will be the behaviour? What will be the behaviour for Overridden Methods?
Cheers, Akhil
Since the reference type of obj is Base, you will be able to access only
those members of Base, and not that of Derived. Now, whose members get
invoked depends upon how the derived class has overriden the base members
etc. Unless the Derv have overridden the methods, Base's methods keep getting
called.
"Akhil" wrote: Hi All,
Can u please explain this.
Base Obj = new Derived(); [Base being the base class and Derived being the derived the class]
Can Obj access methods both of Base and Derived or what will be the behaviour? What will be the behaviour for Overridden Methods?
Cheers, Akhil
This example might help you understand:
class Class1
{
static void Main(string[] args)
{
Base obj = new Base();
obj.Show();
obj = new Derv();
obj.Show(); // This will invoke Derv's method, as it overrides Base's
method
obj.ShowWithNoV irtual(); // This will invoke Base's method, as the Base's
method is not virtual
//obj.DervMethod( ); This won't work as obj refers to a Base type instance
}
}
public class Base
{
public void ShowWithNoVirtu al()
{
Console.WriteLi ne("Base - no virtual");
}
public virtual void Show()
{
Console.WriteLi ne("Base");
}
}
public class Derv : Base
{
public void DervMethod()
{
}
public new void ShowWithNoVirtu al()
{
Console.WriteLi ne("Derv - no virtual");
}
public override void Show()
{
Console.WriteLi ne("Derv");
}
}
"Akhil" wrote: Thanks, But Not Clear though. -- Cheers, Akhil
"googou" <go****@discuss ions.microsoft. com> wrote in message news:D4******** *************** ***********@mic rosoft.com... > Obj only can access methods of base(the Interface of Base ),but the behaviour > of method depend on the Derived(for the Overridden Methods or New > Methods,of couse the behaviour of the other method of Derived is same to > the Base) > > hope it helps > > "Akhil" wrote: > > > Hi All, > > > > Can u please explain this. > > > > Base Obj = new Derived(); [Base being the base class and Derived being > > the derived the class] > > > > Can Obj access methods both of Base and Derived or what will be the > > behaviour? > > What will be the behaviour for Overridden Methods? > > > > Cheers, > > Akhil > > > > > > > > This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Christian Engström |
last post by:
When I compile the below program with Microsoft Visual C++ version 6, I
get the results I expect, which is that the program should write out
base()
derived()
base()
derived(derived)
When I try to compile it with gcc, I instead get the compiler error message
|
by: Dave |
last post by:
Hello NG,
Regarding access-declarations and member using-declarations as used to
change the access level of an inherited base member...
Two things need to be considered when determining an inherited base member's
access level in the derived class: its access level in the base class and
the type of inheritance (public, protected, or private). After this
determination is made, the following possibilities exist for manually
changing the...
|
by: Andy |
last post by:
Hi all,
I have a site with the following architecture:
Common.Web.dll - Contains a CommonPageBase class which inherits
System.Web.UI.Page
myadd.dll - Contains PageBase which inherits CommonPageBase
- Contains myPage which inherits PageBase
Each of these classes overrides OnInit and ties an event handler
|
by: Taran |
last post by:
Hi All,
I tried something with the C++ I know and some things just seem
strange.
consider:
#include <iostream>
using namespace std;
|
by: Dennis Jones |
last post by:
Hello,
I have a couple of classes that look something like this:
class RecordBase
{
};
class RecordDerived : public RecordBase
{
| |
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |