473,387 Members | 1,529 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Inheritance and Types

If I had the following classes,

public class A: B, ISomeInterface
{
}

public class C: A, IAnotherInterface
{
}

Then create an instance class from class C,

[Type] instance = new C();

What are the allowable types for C?
Nov 16 '05 #1
6 906
A, B, C, ISomeInterface, IAnotherInterface

This compiles fine...

class Class1
{
[STAThread]
static void Main(string[] args)
{
ISomeInterface c1 = new C();
IAnotherInterface c2 = new C();
A c3= new C();
B c4= new C();
C c5= new C();
}
}

public class A: B, ISomeInterface
{
}

public class C: A, IAnotherInterface
{
}

public interface ISomeInterface
{
}

public interface IAnotherInterface
{
}

public class B
{
}

"Chris Fink" <Ch*******@discussions.microsoft.com> wrote in message
news:C2**********************************@microsof t.com...
If I had the following classes,

public class A: B, ISomeInterface
{
}

public class C: A, IAnotherInterface
{
}

Then create an instance class from class C,

[Type] instance = new C();

What are the allowable types for C?

Nov 16 '05 #2
Hi,

Did you tried it ?

It's extremely simple to test, just change it to each one possible value
and you will get your answer

tip:
There will be one more that what you may see at beginning :)
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Chris Fink" <Ch*******@discussions.microsoft.com> wrote in message
news:C2**********************************@microsof t.com...
If I had the following classes,

public class A: B, ISomeInterface
{
}

public class C: A, IAnotherInterface
{
}

Then create an instance class from class C,

[Type] instance = new C();

What are the allowable types for C?

Nov 16 '05 #3
Hi,

[Type] can be:

B,
ISomeInterface,
IAnotherInterface,
A
object

or any other classes/interfaces that B implement.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Chris Fink" <Ch*******@discussions.microsoft.com> wrote in message
news:C2**********************************@microsof t.com...
If I had the following classes,

public class A: B, ISomeInterface
{
}

public class C: A, IAnotherInterface
{
}

Then create an instance class from class C,

[Type] instance = new C();

What are the allowable types for C?

Nov 16 '05 #4
What are the implications of using one type over the other?

"Dan Bass" wrote:
A, B, C, ISomeInterface, IAnotherInterface

This compiles fine...

class Class1
{
[STAThread]
static void Main(string[] args)
{
ISomeInterface c1 = new C();
IAnotherInterface c2 = new C();
A c3= new C();
B c4= new C();
C c5= new C();
}
}

public class A: B, ISomeInterface
{
}

public class C: A, IAnotherInterface
{
}

public interface ISomeInterface
{
}

public interface IAnotherInterface
{
}

public class B
{
}

"Chris Fink" <Ch*******@discussions.microsoft.com> wrote in message
news:C2**********************************@microsof t.com...
If I had the following classes,

public class A: B, ISomeInterface
{
}

public class C: A, IAnotherInterface
{
}

Then create an instance class from class C,

[Type] instance = new C();

What are the allowable types for C?


Nov 16 '05 #5
This question is a little deeper.

If you need to ask this question, use the syntac "C c1 = new C();"

I'd google on "object oriented design" and "object oriented programming"
Check this out too...
http://www.firststep.com.au/educatio...ground/oo.html


"Chris Fink" <Ch*******@discussions.microsoft.com> wrote in message
news:5D**********************************@microsof t.com...
What are the implications of using one type over the other?

"Dan Bass" wrote:
A, B, C, ISomeInterface, IAnotherInterface

This compiles fine...

class Class1
{
[STAThread]
static void Main(string[] args)
{
ISomeInterface c1 = new C();
IAnotherInterface c2 = new C();
A c3= new C();
B c4= new C();
C c5= new C();
}
}

public class A: B, ISomeInterface
{
}

public class C: A, IAnotherInterface
{
}

public interface ISomeInterface
{
}

public interface IAnotherInterface
{
}

public class B
{
}

"Chris Fink" <Ch*******@discussions.microsoft.com> wrote in message
news:C2**********************************@microsof t.com...
> If I had the following classes,
>
> public class A: B, ISomeInterface
> {
> }
>
> public class C: A, IAnotherInterface
> {
> }
>
> Then create an instance class from class C,
>
> [Type] instance = new C();
>
> What are the allowable types for C?


Nov 16 '05 #6
Hi Chris,
What are the implications of using one type over the other?
abstraction.

If you use one of the inherited types, your code can follow the Liskov
Substitution Principle, which is to say that your code and deal with the
child type (C) in the same way that it could deal with any of it's base
types, allowing you to substitute an object of the child type for an object
of the base type without changing the client code.

This is fundamental to OO programming.
http://blogs.msdn.com/nickmalik/arch...21/328727.aspx

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"Chris Fink" <Ch*******@discussions.microsoft.com> wrote in message
news:5D**********************************@microsof t.com... What are the implications of using one type over the other?

"Dan Bass" wrote:
A, B, C, ISomeInterface, IAnotherInterface

This compiles fine...

class Class1
{
[STAThread]
static void Main(string[] args)
{
ISomeInterface c1 = new C();
IAnotherInterface c2 = new C();
A c3= new C();
B c4= new C();
C c5= new C();
}
}

public class A: B, ISomeInterface
{
}

public class C: A, IAnotherInterface
{
}

public interface ISomeInterface
{
}

public interface IAnotherInterface
{
}

public class B
{
}

"Chris Fink" <Ch*******@discussions.microsoft.com> wrote in message
news:C2**********************************@microsof t.com...
If I had the following classes,

public class A: B, ISomeInterface
{
}

public class C: A, IAnotherInterface
{
}

Then create an instance class from class C,

[Type] instance = new C();

What are the allowable types for C?


Nov 16 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

37
by: Mike Meng | last post by:
hi all, I'm a newbie Python programmer with a C++ brain inside. I have a lightweight framework in which I design a base class and expect user to extend. In other part of the framework, I heavily...
4
by: KInd | last post by:
Hello All, When is nested class more preferable that Inheritance ? I think with proper inheritance and friend class concept we can get the same flexibility as nested classes Any comments .. Best...
22
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete...
6
by: apm | last post by:
Recently I have had to use a value type for a complex structure because I don't know how to override the = operator. Can the operator ever be overloaded? Or can inheritance be used with value types?
6
by: Pascal Polleunus | last post by:
Hi, I'm wondering if there could be problems related to inheritance in the following scenario (with PostgreSQL 7.4.1)... 1 A-table, abstract. Max 10 B-tables that inherit from A, with...
13
by: Fao | last post by:
Hello, I am having some problems with inheritance. The compiler does not not return any error messages, but when I execute the program, it only allows me to enter the number, but nothing else...
3
by: kikazaru | last post by:
Is it possible to return covariant types for virtual methods inherited from a base class using virtual inheritance? I've constructed an example below, which has the following structure: Shape...
0
by: nejucomo | last post by:
Hi folks, Quick Synopsis: A test script demonstrates a memory leak when I use pythonic extensions of my builtin types, but if I use the builtin types themselves there is no memory leak. ...
0
by: rossabri | last post by:
This topic has been addressed in limited detail in other threads: "sockets don't play nice with new style classes :(" May 14 2005....
6
by: burningodzilla | last post by:
Hi all - I'm preparing to dive in to more complex application development using javascript, and among other things, I'm having a hard time wrapping my head around an issues regarding "inheritance"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.