Inheritance question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Naveen Mukkelli

    Inheritance question

    Hey,

    I want to inherit an abstract class and MessageWindow class.
    can we do that?

    for example,

    abstract class SomeClass
    {
    public void SomeMethod()
    {
    // do something
    }
    }

    can I create a new class which inherits both the above abstract class and
    MessageWindow class?

    public class MyClass : SomeClass, MessageWindow
    {

    }

    Kindly let me know,

    Cheers,

    Naveen.

  • Sam Martin

    #2
    Re: Inheritance question

    no for that you'd need an interface

    e.g.

    public interface IMessageWindow {
    public void DoSomething();
    }

    public class MyClass : SomeClass, IMessageWindow
    {
    // .... other methods/constructir etc.

    #region IMessageWindow implementation

    public void DoSomething() {
    }

    #endregion
    }

    this way classes implementing the interface are forced to implement certain
    methods.

    HTH
    Sam


    "Naveen Mukkelli" <NaveenMukkelli @discussions.mi crosoft.com> wrote in
    message news:5ADEE22E-0A8E-4FB9-9044-6F9EDC4686B6@mi crosoft.com...[color=blue]
    > Hey,
    >
    > I want to inherit an abstract class and MessageWindow class.
    > can we do that?
    >
    > for example,
    >
    > abstract class SomeClass
    > {
    > public void SomeMethod()
    > {
    > // do something
    > }
    > }
    >
    > can I create a new class which inherits both the above abstract class and
    > MessageWindow class?
    >
    > public class MyClass : SomeClass, MessageWindow
    > {
    >
    > }
    >
    > Kindly let me know,
    >
    > Cheers,
    >
    > Naveen.
    >[/color]


    Comment

    • Sean Hederman

      #3
      Re: Inheritance question

      Just to expand on the answer below, you can inherit from only one class, but
      as many interfaces as you like.

      "Sam Martin" <sambomartin@ya hoo.co.uk> wrote in message
      news:OVNZs0pDFH A.4016@TK2MSFTN GP10.phx.gbl...[color=blue]
      > no for that you'd need an interface
      >
      > e.g.
      >
      > public interface IMessageWindow {
      > public void DoSomething();
      > }
      >
      > public class MyClass : SomeClass, IMessageWindow
      > {
      > // .... other methods/constructir etc.
      >
      > #region IMessageWindow implementation
      >
      > public void DoSomething() {
      > }
      >
      > #endregion
      > }
      >
      > this way classes implementing the interface are forced to implement
      > certain methods.
      >
      > HTH
      > Sam
      >
      >
      > "Naveen Mukkelli" <NaveenMukkelli @discussions.mi crosoft.com> wrote in
      > message news:5ADEE22E-0A8E-4FB9-9044-6F9EDC4686B6@mi crosoft.com...[color=green]
      >> Hey,
      >>
      >> I want to inherit an abstract class and MessageWindow class.
      >> can we do that?
      >>
      >> for example,
      >>
      >> abstract class SomeClass
      >> {
      >> public void SomeMethod()
      >> {
      >> // do something
      >> }
      >> }
      >>
      >> can I create a new class which inherits both the above abstract class
      >> and
      >> MessageWindow class?
      >>
      >> public class MyClass : SomeClass, MessageWindow
      >> {
      >>
      >> }
      >>
      >> Kindly let me know,
      >>
      >> Cheers,
      >>
      >> Naveen.
      >>[/color]
      >
      >[/color]


      Comment

      • Ansil MCAD

        #4
        RE: Inheritance question

        hi
        C# does not support multiple inheritance.
        You can inherit only from one class .
        But you can implement multiple interfaces

        Regards
        Ansil Trivandrum


        "Naveen Mukkelli" wrote:
        [color=blue]
        > Hey,
        >
        > I want to inherit an abstract class and MessageWindow class.
        > can we do that?
        >
        > for example,
        >
        > abstract class SomeClass
        > {
        > public void SomeMethod()
        > {
        > // do something
        > }
        > }
        >
        > can I create a new class which inherits both the above abstract class and
        > MessageWindow class?
        >
        > public class MyClass : SomeClass, MessageWindow
        > {
        >
        > }
        >
        > Kindly let me know,
        >
        > Cheers,
        >
        > Naveen.
        >[/color]

        Comment

        Working...