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. difference b/w abstract method and interfaces

difference b/w abstract method and interfaces

Scheduled Pinned Locked Moved C#
question
5 Posts 5 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.
  • G Offline
    G Offline
    George Mathew
    wrote on last edited by
    #1

    what is the difference b/w abstract method and interfaces

    C J L P 4 Replies Last reply
    0
    • G George Mathew

      what is the difference b/w abstract method and interfaces

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      georgemathew2@hotmail.com wrote:

      what is the difference b/w abstract method and interfaces

      I think you mean an abstract class and interface. An abstract class is a class that cannot be instantiated. However, it can contain members (fields, properties, methods, etc.). Some members can be declared as abstract which means that they do not provide any functionality and any derived class is required to implement the behaviour. An interface does not contain any functionality or data. Some descibe it as providing a contract. If you implement the interface then you are contractually obliged to implement the members it specifies.


      Upcoming FREE developer events: * Developer Day Scotland My website

      1 Reply Last reply
      0
      • G George Mathew

        what is the difference b/w abstract method and interfaces

        J Offline
        J Offline
        J4amieC
        wrote on last edited by
        #3

        Nothing, but then you asked the wrong question You should have asked "What is the difference between an abstract class and an interfaces?" In which case the answer would have been that an abstract class can contain some implementation detail whereas an interface just defines a contract that an implementing class must conform to.

        1 Reply Last reply
        0
        • G George Mathew

          what is the difference b/w abstract method and interfaces

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Hi I guess you mean between an abstract class and an interface. An Interface is basically an abstract class. with an abstract class you define a class that can not be instanced with new the abstract class example of this interface:

          public interface MyInterface
          {
          void Foo(int Param);
          }

          would be:

          public abstract class MyAbstractClass
          {
          public abstract void Foo(int Param);
          }

          so you see 2 important differences: 1) in an interface you don't need a modifyer as public/private/internal on the members. they all have the same visibility as the interface (int this case public) 2) in an interface every member is implicit abstract. but still there's a difference between an interface and a class. in an abstract class you can do this:

          public abstract class MyAbstractClass
          {
          protected int myProtectedMember;
          public abstract void Foo(int Param);
          Public MyAbstractClass()
          {
          myProtectedMember = 100;
          }
          protected virtual void Inc(ref int Value)
          {
          Value++;
          }
          }

          --> you can implement functions that are accessible by a derived class only. a protected member is a private member that is visible for derived classes as well. --> the interface won't let you implement fuctions directly on it. --> an interface can not have a constructor and one more important difference between an abstract class and an interface: you can derive a class from exactly one other class, but from as many interfaces you want. there are some more differences (like implementation of classes that inherit a class/interface) but you'll see if you try:)

          1 Reply Last reply
          0
          • G George Mathew

            what is the difference b/w abstract method and interfaces

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

            In my experience "b/w" means "backed with" so I have no idea what your question means.

            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