raj a
practical example for abstract class
By raj a in OOP/OOD on Sep 18 2008
  • raman ji singh
    Apr, 2015 25

    Abstract class is keywords its makes the functionality is different are declared abstract class

    • 0
  • Manju lata Yadav
    Jul, 2014 22

    Abstract classes are used when you have a number of classes which are very similar in their behaviour/ purpose - ie they all have the same methods/member variables except that the definition of one or more methods in each class varies somewhat. In this case you create yor abstract class which takes all methods common to the other classes, but the functions that differ are declared abstract and must be defined in sub classes.

    • 0
  • Manju lata Yadav
    Jul, 2014 22

    Abstract classes are used when you have a number of classes which are very similar in their behaviour/ purpose - ie they all have the same methods/member variables except that the definition of one or more methods in each class varies somewhat. In this case you create yor abstract class which takes all methods common to the other classes, but the functions that differ are declared abstract and must be defined in sub classes.

    • 0
  • kalit sikka
    Jul, 2009 21

    Abstract classes

    The abstract modifier is used to indicate that a class is incomplete and that it is intended to be used only as a base class. An abstract class differs from a non-abstract class is the following ways:

    • An abstract class cannot be instantiated directly, and it is a compile-time error to use the new operator on an abstract class. While it is possible to have variables and values whose compile-time types are abstract, such variables and values will necessarily either be null or contain references to instances of non-abstract classes derived from the abstract types.
    • An abstract class is permitted (but not required) to contain abstract members.
    •  An abstract class cannot be sealed.

    When a non-abstract class is derived from an abstract class, the non-abstract class must include actual implementations of all inherited abstract members. Such implementations are provided by overriding the abstract members. For example:

    abstract class A
    {
     public abstract void F();
    }
    abstract class B: A
    {
     public void G() {}
    }
    class C: B
    {
       public override void F() {
       // actual implementation of F
      }
    }

    the abstract class A introduces an abstract method F. Class B introduces an additional method G, but since it doesn’t provide an implementation of F, B must also be declared abstract. Class C overrides F and provides an actual implementation. Since there are no abstract members in C, C is permitted (but not required) to be non-abstract.

    Visit: http://kalitinterviewquestions.blogspot.com/

     

    • 0
  • simbu v
    Jun, 2009 20

    Can fly Cannot fly

    • 0
  • simbu v
    Jun, 2009 20

    Cannot fly Can fly

    • 0
  • ashok more
    Apr, 2009 25

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace TestConsoleApp
    {
        public abstract class Duck
        {
            public abstract string Fly();

            public void Run()
            {
                Console.Write(Fly().ToString());
            }
        }

        public class WoodenDuck : Duck
        {

            public override string Fly()
            {
                return "Cannot fly";
            }
        }

        public class LiveDuck : Duck
        {
            public override string Fly()
            {
                return "Can fly";
            }
        }

        public class TestApp
        {
            public void Test()
            {
                Duck duck;
                duck = new LiveDuck();
                duck.Run();

                duck = new WoodenDuck();
                duck.Run();
            }
        }
    }

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS