Question about inheritance

  • Thread starter Thread starter tired_of_spaghetti
  • Start date Start date
T

tired_of_spaghetti

As I understand it, the virtual keyword is necessary and also in a
derived class you must use the override keyword so what if :

1) you don't use the override keyword ?

2) Suppose you have a class hieracy that looks like

public class Base
{
public virtual void myMethod()
{...
}
}

public class Derived : Base
{
public override void myMethod()
{ ...
}
}

public class MoreDerived : Derived
{
public override void myMethod()
{ ...
}
}

In function main()
{
Base myObject1 = new Base();
Base myObject2 = new Derived();
Derived myObject3 = new MoreDerived();

Since myMethod() in class Derived is not virtual which myMethod()
would be called on myObject3 ?

3) What is the default export policy for classes, members, and methods
- public or private ?

Thanks,
Ted
 
<[email protected]> a écrit dans le message de (e-mail address removed)...

| In function main()
| {
| Base myObject1 = new Base();
| Base myObject2 = new Derived();
| Derived myObject3 = new MoreDerived();
|
| Since myMethod() in class Derived is not virtual which myMethod()
| would be called on myObject3 ?

Derived uses the override directive which also implies virtual, so the
MoreDerived version would be called.

| 3) What is the default export policy for classes, members, and methods
| - public or private ?

Internal is the default for classes and interfaces, and private for members.

Joanna
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top