logo
 
  •  
  • Thread Rating
    70.0%
    Rate this Thread
    Double click on boxes to rate this thread
  • DotNet Interview Questions
  • What is the difference between abstract class and interface?
    If a class is to serve the purpose of providing common fields and members to all subclasses, we
    create an Abstract
    class. For creating an abstract class, we make use of the abstract keyword. Such a class cannot
    be instantiated.
    Syntax below:
    abstract public class Vehicle { }
    Public interface IVehicle //As a convention, an interface is prefixed by letter I
    {
    Boolean HasFourWheels()
    }
    Time to discuss the Difference between Abstract Class and Interface
    1) A class may inherit only one abstract class, but may implement multiple number of Interfaces.
    Say a class named Car
    needs to inherit some basic features of a vehicle, it may inherit from an Aabstract class named
    Vehicle. A car may be
    Page 5
    of any kind, it may be a vintage car, a sedan, a coupe, or a racing car. For these kind of
    requirements, say a car
    needs to have only two seats (means it is a coupe), then the class Car needs to implement a
    member field from an
    interface, that we make, say ICoupe.
    2) Members of an abstract class may have any access modifier, but members of an interface are
    public by default, and
    cant have any other access modifier.
    3) Abstract class methods may OR may not have an implementation, while methods in an
    Interface only have a definition,
    no implementation.

    Explain the access specifiers Public, Private, Protected, Friend, Internal, Default
    1. PUBLIC
    As the name specifies, it can be accessed from anywhere. If a member of a class is defined as
    public then it can be
    accessed anywhere in the class as well as outside the class. This means that objects can access
    and modify public
    fields, properties, methods.
    2. PRIVATE
    As the name suggests, it can't be accessed outside the class. Its the private property of the class
    and can be
    accessed only by the members of the class.
    3. FRIEND/INTERNAL
    Friend & Internal mean the same. Friend is used in VB.NET. Internal is used in C#. Friends can
    be accessed by all
    classes within an assembly but n
    By Uma - Sep 04 2009 Reply » Save » Print »

Login to post your reply