Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Abstract class implementing interface [modified]

Abstract class implementing interface [modified]

Scheduled Pinned Locked Moved C#
csharpquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SeeBees
    wrote on last edited by
    #1

    There's an abstrat class in .NET public abstract class CollectionBase : IList, ICollection, IEnumerable{...} However, No definition or declaration of IList's functions are found in CollectionBase. How could this ever happen? If it's an abstract class, it's allowed to not implement its interface? Thanks everybody:-D

    P 1 Reply Last reply
    0
    • S SeeBees

      There's an abstrat class in .NET public abstract class CollectionBase : IList, ICollection, IEnumerable{...} However, No definition or declaration of IList's functions are found in CollectionBase. How could this ever happen? If it's an abstract class, it's allowed to not implement its interface? Thanks everybody:-D

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      Yes, only concrete classes must.

      S 1 Reply Last reply
      0
      • P PIEBALDconsult

        Yes, only concrete classes must.

        S Offline
        S Offline
        SeeBees
        wrote on last edited by
        #3

        Thanks, but why won't the following code compile? using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { interface A{ void A(); } abstract class B : A { // public abstract void A(); } } I got an error! The compiler says I should implement A.A() in abstract class B.

        M P 2 Replies Last reply
        0
        • S SeeBees

          Thanks, but why won't the following code compile? using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { interface A{ void A(); } abstract class B : A { // public abstract void A(); } } I got an error! The compiler says I should implement A.A() in abstract class B.

          M Offline
          M Offline
          mav northwind
          wrote on last edited by
          #4

          That's exactly the same concept - you're not declaring a concrete class anywhere. If you add

          class C : B
          {
          // No implementation of A here as well
          }

          then you'll get a compiler error.

          Regards, mav -- Black holes are the places where God divided by 0...

          S 1 Reply Last reply
          0
          • M mav northwind

            That's exactly the same concept - you're not declaring a concrete class anywhere. If you add

            class C : B
            {
            // No implementation of A here as well
            }

            then you'll get a compiler error.

            Regards, mav -- Black holes are the places where God divided by 0...

            S Offline
            S Offline
            SeeBees
            wrote on last edited by
            #5

            In my previous example, the abstract B results in an error if it doesn't contain method A.A(). So I guess it is necessary to implement an interface even in an abstract class:-O

            1 Reply Last reply
            0
            • S SeeBees

              Thanks, but why won't the following code compile? using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { interface A{ void A(); } abstract class B : A { // public abstract void A(); } } I got an error! The compiler says I should implement A.A() in abstract class B.

              P Offline
              P Offline
              PIEBALDconsult
              wrote on last edited by
              #6

              My earlier answer wasn't quite as correct as I would have preferred. :-D You need the abstract stub, but it's still not an implementation.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups