OOPS Inteview

Embed Size (px)

Citation preview

  • 7/25/2019 OOPS Inteview

    1/11

    C# OOPs interview questions and answers

    1. What is object-oriented programming (OOP)?

    OOP is a technique to develop logical modules, such as classes that contain properties, methods, fields, and events. An object is created in the program to represent aclass. Therefore, an object encapsulates all the features, such as data and behavior that are associated to a class. OOP allows developers to develop modular programs

    and assemble them as software. Objects are used to access data and behaviors of different software modules, such as classes, namespaces, and sharable

    assemblies. .NET ramewor! supports onl" OOP languages, such as #isual $asic .NET, #isual %&, and #isual %''.

    2. What is a class?

    A class describes all the attributes of objects, as well as the methods that implement the behavior of member objects. (t is a comprehensive data t"pe, which

    represents a blue print of objects. (t is a template of object.

    A class can be defined as the primar" building bloc! of OOP. (t also serves as a template that describes the properties, state, and behaviors common to a particular

    group of objects.

    A class contains data and behavior of an entit". or e)ample, the aircraft class can contain data, such as model number, categor", and color and behavior, such as

    duration of flight, speed, and number of passengers. A class inherits the data members and behaviors of other classes b" e)tending from them.

    3. What is an object?

    The" are instance of classes. (t is a basic unit of a s"stem. An object is an entit" that has attributes, behavior, and identit". Attributes and behavior of an object are

    defined b" the class definition.

    4. What is the relationship between a class and an object?

    A class acts as a blue*print that defines the properties, states, and behaviors that are common to a number of objects. An object is an instance of the class. or

    e)ample, "ou have a class called Vehicleand Caris the object of that class. +ou can create an" number of objects for the class named Vehicle, such

    as Van, Truck, and Auto.

    The newoperator is used to create an object of a class. hen an object of a class is instantiated, the s"stem allocates memor" for ever" data member that is present

    in the class.

    . !"plain the basic #eat$res o# OOPs.

    The following are the four basic features of OOP-

    %bstraction* efers to the process of e)posing onl" the relevant and essential data to the users without showing unnecessar" information.

    Pol&morphism* Allows "ou to use an entit" in multiple forms.

    !ncaps$lation* Prevents the data from unwanted access b" binding of code and data in a single unit called object.

    'nheritance* Promotes the reusabilit" of code and eliminates the use of redundant code. (t is the propert" through which a child class obtains all the

    features defined in its parent class. hen a class inherits the common properties of another class, the class inheriting the properties is called a derived

    class and the class that allows inheritance of its common properties is called a base c lass.

    . What is the di##erence between arra&s and collection?

    %rra&-

    /. +ou need to specif" the si0e of an arra" at the time of its declaration. (t cannot be resi0ed d"namicall".

    1. The members of an arra" should be of the same data t"pe.

    ollection-

    /. The si0e of a collection can be adjusted d"namicall", as per the user2s requirement. (t does not have fi)ed si0e.

    1. %ollection can have elements of different t"pes.

  • 7/25/2019 OOPS Inteview

    2/11

    3. *. What are collections and generics?

    3. A collection can be defined as a group of related items that can be referred to as a single unit. TheSystem.Collectionsnamespace provides "ou with

    man" classes and interfaces. 4ome of them are *ArrayList, List, Stack, ICollection, IEnumerable, and IDictionary. 5enerics provide the t"pe*

    safet" to "our class at the compile time. hile creating a data structure, "ou never need to specif" the data t"pe at the time of declaration.

    The System.Collections.Genericnamespace contains all the generic collections.

    . +. ,ow can &o$ preent &o$r class to be inherited #$rther?

    6. +ou can prevent a class from being inherited further b" defining it with the sealed!e"word.

    *. . What is the inde" al$e o# the #irst element in an arra&?

    7. (n an arra", the inde) value of the first element is 080ero9.

    . 1/. an &o$ speci#& the accessibilit& modi#ier #or methods inside the inter#ace?

    /:. All the methods inside an interface are alwa"s public, b" default. +ou cannot specif" an" other access modifier for them.

    11. 11. 's it possible #or a class to inherit the constr$ctor o# its base class?

    /1. No, a class cannot inherit the constructor of its base class.

    13. 12. ,ow is method oerriding di##erent #rom method oerloading?

    /3. Overriding involves the creation of two or more methods with the same name and same signature in different classes 8one of them should be parent class

    and other should be child9.

    Overloading is a concept of using a method at different places with same name and different signatures within the same class.

    13. What is the di##erence between a class and a str$ct$re?

    lass-

    /. A class is a reference t"pe.

    1. hile instantiating a class, %; allocates memor" for its instance in heap.

    destructor.

    0tr$ct$re-

    /. A structure is a value t"pe.

    1. (n structure, memor" is allocated on stac!.

    destructor and members can be initialia0ed automaticall".

    14. What are similarities between a class and a str$ct$re.

    4tructures and classes are the two most important data structures that are used b" programmers to build modular programs b" using OOP languages, such as #isual

    $asic .NET, and #isual %&. The following are some of the similarities between a class and a structure-

  • 7/25/2019 OOPS Inteview

    3/11

    Access specifiers, such as public, priate, and protected, are identicall" used in structures and classes to restrict the access of their data and

    methods outside their bod".

    The access level for class members and struct members, including nested classes and structs, is private b" default. Private nested t"pes are not accessible

    from outside the containing t"pe.

    $oth can have constructors, methods, properties, fields, constants, enumerations, events, and event handlers.

    $oth structures and classes can implement interfaces to use multiple*inheritance in code.

    $oth structures and classes can have constructors with parameter.

    $oth structures and classes can have delegates and events.

    1. What is a m$lticast delegate?

    Each delegate object holds reference to a single method. ?owever, it is possible for a delegate object to hold references of and invo!e multiple methods. 4uch delegate

    objects are called multicast delegates or combinable delegates.

    1. an &o$ declare an oerridden method to be static i# the original method is not static?

    No. Two virtual methods must have the same signature.

    1*. Wh& is the irt$al e&word $sed in code?

    The irtual!e"word is used while defining a class to specif" that the methods and the properties of that class can be overridden in derived classes.

    1+. an &o$ allow a class to be inherited b$t preent a method #rom being oerridden in ?

    +es. @ust declare the class publicand ma!e the method sealed.

    1. e#ine en$meration?

    Enumeration is defined as a value t"pe that consists of a set of named values. These values are constants and are called enumerators. An enumeration t"pe is declared

    using the enum!e"word. Each enumerator in an enumeration is associated with an underl"ing t"pe that is set, b" default, on the enumerator. The following is ane)ample that creates an enumeration to store different varieties of fruits-

    enum "ruits #$an%o& Apple& oran%e& Guaa'(

    (n the preceding e)ample, an enumeration "ruitsis created, where number 0is associated with $an%o, number )with Apple, number *with +ran%e, and

    number ,with Guaa. +ou can access the enumerators of an enumeration b" these values.

    2/. 'n which namespace all .5!6 collection classes are contained?

    The System.Collectionsnamespace contains all the collection classes.

    21. 's it a good practice to handle e"ceptions in code?

    +es, "ou must handle e)ceptions in code so that "ou can deal with an" une)pected situations that occur when a program is running. or e)ample, dividing a number b"

    0ero or passing a string value to a variable that holds an integer value would result in an e)ception.

    22. !"plain the concept o# constr$ctor?

    %onstructor is a special method of a class, which is called automaticall" when the instance of a class is created. (t is created with the same name as the class and

    initiali0es all class members, whenever "ou access the class. The main features of a constructor are as follows-

    %onstructors do not have an" return t"pe

    %onstructors are alwa"s public

    (t is not mandator" to declare a constructor it is invo!ed automaticall" b" .NET ramewor!.

  • 7/25/2019 OOPS Inteview

    4/11

    23. an &o$ inherit priate members o# a class?

    No, "ou cannot inherit priatemembers of a class because priatemembers are accessible onl" to that class and not outside that class.

    24. oes .5!6 s$pport m$ltiple inheritance?

    .NET does not support multiple inheritance directl" because in .NET, a class cannot inherit from more than one class. .NET supports multiple inheritance through

    interfaces.

    2. ,ow has e"ception handling changed in .5!6 7ramewor 4./?

    (n .NET 3.:, a new namespace, System.-untime.EceptionSerices, has been introduced which contains the following classes for handling e)ceptions in a better

    and advanced manner-

    /andlerocessCorruptedStateEceptionsAttribute%lass * Enables managed code to handle the corrupted state e)ceptions that occur in an

    operating s"stem. These e)ceptions cannot be caught b" specif"ing the try...catchbloc!. To handle such e)ceptions, "ou can appl" this attribute to the

    method that is assigned to handle these e)ceptions.

    "irstChanceEceptionEentAr%s%lass * 5enerates an event whenever a managed e)ception first occurs in "our code, before the common language

    runtime begins searching for event handlers.

    2. What is a delegate?

    A delegate is similar to a class that is used for storing the reference to a method and invo!ing that method at runtime, as required. A delegate can hold the reference of

    onl" those methods whose signatures are same as that of the delegate. 4ome of the e)amples of delegates are t"pe*safe functions, pointers, or callbac!s.

    2*. What is the s&nta" to inherit #rom a class in ?

    hen a class is derived from another class, then the members of the base class become the members of the derived class. The access modifier used while accessing

    members of the base class specifies the access status of the base class members inside the derived class.

    The s"nta) to inherit a class from another class in %& is as follows-

    class $y1ewClass 2 $y3aseclass

    2+. 0tate the #eat$res o# an inter#ace.

    An interface is a template that contains onl" the signature of methods. The signature of a method consists of the numbers of parameters, the t"pe of parameter 8value,

    reference, or output9, and the order of parameters. An interface has no implementation on its own because it contains onl" the definition of methods without an"

    method bod". An interface is defined using the inter4ace!e"word. Boreover, "ou cannot instantiate an interface. The various features of an interface are as follows-

    An interface is used to implement multiple inheritance in code. This feature of an interface is quite different from that of abstract classes because a class

    cannot derive the features of more than one class but can easil" implement multiple interfaces.

    (t defines a specific set of methods and their arguments.

    #ariables in interface must be declared as public, static, and 4inalwhile methods must be publicand abstract.

    A class implementing an interface must implement all of its methods.

    An interface can derive from more than one interface.

    2. an &o$ $se the 8throws8 cla$se to raise an e"ception?

    No, the throwsclause cannot be used to raise an e)ception. The throwstatement signals the occurrence of an e)ception during the e)ecution of a program. hen the

    program encounters a throwstatement, the method terminates and returns the error to the calling method.

    3/. e#ine an arra&.

    An arra" is defined as a homogeneous collection of elements, stored at contiguous memor" locations, which can be referred b" the same variable name. All the

    elements of an arra" variable can be accessed b" inde) values. An (nde) value specifies the position of a particular element in an arra" variable.

    31. What are methods?

  • 7/25/2019 OOPS Inteview

    5/11

    Bethods are the building bloc!s of a class, in which the" are lin!ed together to share and process data to produce the result. (n other words, a method is a bloc! of

    code that contains a series of statements and represents the behavior of a class. hile declaring a method "ou need to specif" the access specifier, the return value,

    the name of the method, and the method parameters. All these combined together is called the signature of the method.

    32. What is a namespace?

    Namespace is considered as a container that contains functionall" related group of classes and other t"pes.

    33. o eents hae ret$rn t&pe?

    No, events do not have return t"pe.

    34. What is the #$nction o# the 6r&-atch-7inall& bloc?

    The trybloc! encloses those statements that can cause e)ception and the catchbloc! handles the e)ception, if it occurs. %atch bloc! contains the statements that

    have to be e)ecuted, when an e)ception occurs. The4inallybloc! alwa"s e)ecutes, irrespective of the fact whether or not an e)ception has occurred.

    The 4inallybloc! is generall" used to perform the cleanup process. (f an" e)ception occurs in the trybloc!, the program control directl" transfers to its

    corresponding catchbloc! and later to the 4inallybloc!. (f no e)ception occurs inside the trybloc!, then the program control transfers directl" to

    the 4inallybloc!.

    3. ,ow can &o$ preent a class #rom oerriding in and 9is$al :asic?

    +ou can prevent a class from overriding in %& b" using the sealed!e"word whereas, the 1otInheritable!e"word is used to prevent a class from overriding in

    #isual $asic.

    3. What are abstract classes? What are the distinct characteristics o# an abstract class?

    An abstract class is a class that cannot be instantiated and is alwa"s used as a base class.

    The following are the characteristics of an abstract class-

    +ou cannot instantiate an abstract class directl". This implies that "ou cannot create an object of the abstract class it must be inherited.

    +ou can have abstract as well as non*abstract members in an abstract class.

    +ou must declare at least one abstract method in the abstract class.

    An abstract class is alwa"s public.

    An abstract class is declared using the abstract!e"word.

    The basic purpose of an abstract class is to provide a common definition of the base class that multiple derived classes can share.

    3*. ;ie a brie# description o# properties in and the adantages that are obtained b& $sing them in programs.

    (n %&, a propert" is a wa" to e)pose an internal data element of a class in a simple and intuitive manner. (n other words, it is a simple e)tension of data fields. +ou can

    create a propert" b" defining an e)ternall" available name and then writing the setand %etpropert" accessors. The get propert" accessor is used to return the

    propert" value. The set propert" accessor is used to assign a new value to the propert".

    3+. !"plain di##erent t&pes o# inheritance.

    (nheritance in OOP is of four t"pes-

    0ingle inheritance* %ontains one base class and one derived class

    ,ierarchical inheritance* %ontains one base class and multiple derived classes of the same base class

  • 7/25/2019 OOPS Inteview

    6/11

    3. =o$ hae de#ined a destr$ctor in a class that &o$ hae deeloped b& $sing the programming lang$age b$t the destr$ctor neer e"ec$ted. Wh&

    did the destr$ctor not e"ec$te?

    The runtime environment automaticall" invo!es the destructor of a class to release the resources that are occupied b" variables and methods of an object. ?owever, in

    %&, programmers cannot control the timing for invo!ing destructors, as 5arbage %ollector is onl" responsible for releasing the resources used b" an object. 5arbage

    %ollector automaticall" gets information about unreferenced objects from .NET2s runtime environment and then invo!es the "inali5e67method.

    Although, it is not preferable to force 5arbage %ollector to perform garbage collection and retrieve all inaccessible memor", programmers can use

    the Collect67method of the 5arbage %ollector class to forcefull" e)ecute 5arbage %ollector.

    4/. What is a hashtable?

    /ashtableis a data structure that implements the IDictionaryinterface. (t is used to store multiple items and each of these items is associated with a unique string

    !e". Each item can be accessed using the !e" associated with it. (n short, hashtable is an object holding the !e"*value pairs.

    41. an $sers de#ine their own e"ceptions in code?

    +es, customi0ed e)ceptions can be defined in code b" deriving from the System.Eceptionclass.

    42. 's it possible to e"ec$te two catch blocs?

    +ou are allowed to include more than one catchbloc! in "our program however, it is not possible to e)ecute them in one go. henever, an e)ception occurs in "our

    program, the correct catchbloc! is e)ecuted and the control goes to the 4inallybloc!.

    43. What do &o$ mean b& data encaps$lation?

    Cata encapsulation is a concept of binding data and code in single unit called object and hiding all the implementation details of a class from the user. (t prevents

    unauthori0ed access of data and restricts the user to use the necessar" data onl".

    44. What is the di##erence between proced$ral and object-oriented programming?

    Procedural programming is based upon the modular approach in which the larger programs are bro!en into procedures. Each procedure is a set of instructions that are

    e)ecuted one after another. On the other hand, OOP is based upon objects. An object consists of various elements, such as methods and variables.

    Access modifiers are not used in procedural programming, which implies that the entire data can be accessed freel" an"where in the program. (n OOP, "ou can specif"

    the scope of a particular data b" using access modifiers * public, priate, internal, protected, and protectedinternal.

    4. !"plain the concept o# destr$ctor?

    A destructor is a special method for a class and is invo!ed automaticall" when an object is finall" destro"ed. The name of the destructor is also same as that of the

    class but is followed b" a prefi) tilde 8D9.

    A destructor is used to free the d"namic allocated memor" and release the resources. +ou can, however, implement a custom method that allows "ou to control object

    destruction b" calling the destructor.

    The main features of a destructor are as follows-

    Cestructors do not have an" return t"pe

    4imilar to constructors, destructors are also alwa"s public

    Cestructors cannot be overloaded.

    4. an &o$ declare a priate class in a namespace?

    The classes in a namespace are internal, b" default. ?owever, "ou can e)plicitl" declare them as publiconl" and not as priate, protected, or protected

    internal. The nested classes can be declared as priate,protected, or protected internal.

    4*. % str$ct$re in can implement one or more inter#aces. 's it tr$e or #alse?

    +es, it is true. ;i!e classes, in %&, structures can implement one or more interfaces.

    4+. What is a static constr$ctor?

    4tatic constructors are introduced with %& to initiali0e the static data of a class. %; calls the static constructor before the first instance is created.

    The static constructor has the following features-

  • 7/25/2019 OOPS Inteview

    7/11

    No access specifier is required to define it.

    +ou cannot pass parameters in static constructor.

    A class can have onl" one static constructor.

    (t can access onl" static members of the class.

    (t is invo!ed onl" once, when the program e)ecution begins.

    4. What are the di##erent wa&s a method can be oerloaded?

    The different wa"s to overload a method are given as follows-

    $" changing the number of parameters used

    $" changing the order of parameters

    $" using different data t"pes for the parameters

    /. i##erentiate between an abstract class and an inter#ace.

    %bstract lass-

    /. A class can e)tend onl" one abstract class

    1. The members of abstract class can be private as well as protected.

  • 7/25/2019 OOPS Inteview

    8/11

    4tac!s refer to a list in which all items are accessed and processed on the ;ast*(n*irst*Out 8;(O9 basis. (n a stac!, elements are inserted 8push operation9 and deleted

    8pop operation9 from the same end called top.

    Fueues refer to a list in which insertion and deletion of an item is done on the irst*(n*irst*Out 8(O9 basis. The items in a queue are inserted from the one end,

    called the rearend, and are deleted from the other end, called the #rontend of the queue.

    2. e#ine an eent.

    henever an action ta!es place in a class, that class provides a notification to other classes or objects that are assigned to perform particular tas!s. These notifications

    are called events. or e)ample, when a button is clic!ed, the class generates an event called %lic!. An event can be declared with the help of the event !e"word.

    3. What are str$ct$res?

    4tructure is a heterogeneous collection of elements referenced b" the same name. A structure is declared using the struct !e"word. The following is an e)ample that

    creates a structure to store an emplo"ee2s information-

    structemp

    {

    fixedintempID[15];

    fixedcharname[30];

    fixedcharaddr[50];

    fixedchardept[15];

    fixedchardesig[15];}

    The preceding e)ample defines a structure empand the members of this s tructure specif" the information of an emplo"ee.

    4. When do &o$ reall& need to create an abstract class?

    e define abstract classes when we define a template that needs to be followed b" all the derived classes.

    ---------------------------------------------------------------------------------------------------------------------

    -----------------

    hat is Pol"morphismsG

    Pol"morphism means one interface and man" forms. Pol"morphism is a characteristics of being able to assign a different meaning or usage to something

    in different conte)ts specificall" to allow an entit" such as a variable, a function or an object to have more than one form.

    There are two t"pes of Pol"morphism.

    ompile timefunction or operator overloading

    @$ntime(nheritence H virtual functions

    hat is Abstract methodG

    Abstract method doesn2t provide the implementation H forces the derived class to override the method.

    hat is #irtual methodG

    #irtual Bethod has implementation H provide the derived class with the option to override it.

    http://www.dotnetfunda.com/interviews/show/64/what-is-polymorphismshttp://www.dotnetfunda.com/interviews/show/65/what-is-abstract-methodhttp://www.dotnetfunda.com/interviews/show/66/what-is-virtual-methodhttp://www.dotnetfunda.com/interviews/show/64/what-is-polymorphismshttp://www.dotnetfunda.com/interviews/show/65/what-is-abstract-methodhttp://www.dotnetfunda.com/interviews/show/66/what-is-virtual-method
  • 7/25/2019 OOPS Inteview

    9/11

    %an 4truct be inheritedG

    No, 4truct can2t be inherited as this is implicitl" sealed.

    hat is ObjectG

    Object is an"thing that is identifiable as a single material item.

    hat is %lassG

    A %lass is the generic definition of what an object is a template.

    The !e"word class in %& indicates that we are going to define a new class 8t"pe of object9

    hat is 4tatic fieldG

    To indicate that a field should onl" be stored once no matter how man" instance of the class we create.

    hat is 4tatic BethodG

    (t is possible to declare a method as 4tatic provided that the" don2t attempt to access an" instance data or other instance methods.

    hat is (nheritanceG

    (t provides a convenient wa" to reuse e)isting full" tested code in different conte)t thereb" saving lot of coding.

    (nheritance of classes in %& is alwa"s implementation (nheritance.

    hat is #irtual !e"wordG

    This !e"word indicates that a member can be overridden in a child class. (t can be applied to methods, properties, inde)es and events.

    hat is New modifiersG

    The new modifiers hides a member of the base class. %& supports onl" hide b" signature.

    http://www.dotnetfunda.com/interviews/show/67/can-struct-be-inheritedhttp://www.dotnetfunda.com/interviews/show/82/what-is-objecthttp://www.dotnetfunda.com/interviews/show/83/what-is-classhttp://www.dotnetfunda.com/interviews/show/84/what-is-static-fieldhttp://www.dotnetfunda.com/interviews/show/85/what-is-static-methodhttp://www.dotnetfunda.com/interviews/show/87/what-is-inheritancehttp://www.dotnetfunda.com/interviews/show/88/what-is-virtual-keywordhttp://www.dotnetfunda.com/interviews/show/89/what-is-new-modifiershttp://www.dotnetfunda.com/interviews/show/67/can-struct-be-inheritedhttp://www.dotnetfunda.com/interviews/show/82/what-is-objecthttp://www.dotnetfunda.com/interviews/show/83/what-is-classhttp://www.dotnetfunda.com/interviews/show/84/what-is-static-fieldhttp://www.dotnetfunda.com/interviews/show/85/what-is-static-methodhttp://www.dotnetfunda.com/interviews/show/87/what-is-inheritancehttp://www.dotnetfunda.com/interviews/show/88/what-is-virtual-keywordhttp://www.dotnetfunda.com/interviews/show/89/what-is-new-modifiers
  • 7/25/2019 OOPS Inteview

    10/11

    hat is Abstract %lassG

    Abstract class is a class that can not be instantiated, it e)ists e)tensivel" for inheritance and it must be inherited. There are scenarios in which it is usefulto define classes that is not intended to instantiate because such classes normall" are used as base*classes in inheritance hierarchies, we call such

    classes abstract classes.

    Abstract classes cannot be used to instantiate objects because abstract classes are incomplete, it ma" contain onl" definition of the properties or

    methods and derived classes that inherit this implements it2s properties or methods.

    4tatic, #alue T"pes H interface doesn2t support abstract modifiers. 4tatic members cannot be abstract. %lasses with abstract member must also be

    abstract.

    7or detailed e"ample read this articlehttpAAwww.dotnet#$nda.comAarticlesAarticle4*-abstract-class--e"plained.asp"

    hat is 4ealed modifiersG

    4ealed t"pes cannot be inherited H are concrete.

    4ealed modifiers can also be applied to instance methods, properties, events H inde)es. (t can2t be applied to static members.

    4ealed members are allowed in sealed and non*sealed classes.

    hat is an (nterfaceG

    An interface is a contract H defines the requisite behavior of generali0ation of t"pes.

    An interface mandates a set of behavior, but not the implementation. (nterface must be inherited. e can2t create an instance of an interface.

    An interface is an arra" of related function that must be implemented in derived t"pe. Bembers of an interface are implicitl" public H abstract.

    An interface can inherit from another interface.

    hen to use (nterface over abstract classG

    Abstract %lasses- %lasses which cannot be instantiated. This means one cannot ma!e a object of this class or in other wa" cannot create object b" sa"ing

    %lassAbs abs I new %lassAbs89 where %lassAbs is abstract class.

    Abstract classes contains have one or more abstarct methods, ie method bod" onl" no implementation.

    (nterfaces- These are same as abstract classes onl" difference is we can onl" define method definition and no implementation.

    hen to use wot depends on various reasons. One being design choice.One reason for using abstarct classes is we can code common

    functionalit" and force our developer to use it. ( can have a complete

    class but ( can still mar! the class as abstract.

    Ceveloping b" interface helps in object based communication.

    hat is pure virtual functionG

    hen "ou define onl" function protot"pe in a base class without and do the complete implementation in derived class. This base class is called abstractclass and client wonJt able to instantiate an object using this base class.

    A pure virtual function is a function that must be overridden in a derived class and need not be defined. A virtual function is declared to be KpureK usingthe curious KI:K

    s"nta)-

    class $ase L

    public-

    void f/89 >> not virtualvirtual void f189 >> virtual, not pure

    virtual void f> pure virtual

    M

    http://www.dotnetfunda.com/interviews/show/90/what-is-abstract-classhttp://www.dotnetfunda.com/articles/article467-abstract-class--explained.aspxhttp://www.dotnetfunda.com/articles/article467-abstract-class--explained.aspxhttp://www.dotnetfunda.com/articles/article467-abstract-class--explained.aspxhttp://www.dotnetfunda.com/interviews/show/91/what-is-sealed-modifiershttp://www.dotnetfunda.com/interviews/show/92/what-is-an-interfacehttp://www.dotnetfunda.com/interviews/show/332/when-to-use-interface-over-abstract-classhttp://www.dotnetfunda.com/interviews/show/333/what-is-pure-virtual-functionhttp://www.dotnetfunda.com/interviews/show/90/what-is-abstract-classhttp://www.dotnetfunda.com/articles/article467-abstract-class--explained.aspxhttp://www.dotnetfunda.com/interviews/show/91/what-is-sealed-modifiershttp://www.dotnetfunda.com/interviews/show/92/what-is-an-interfacehttp://www.dotnetfunda.com/interviews/show/332/when-to-use-interface-over-abstract-classhttp://www.dotnetfunda.com/interviews/show/333/what-is-pure-virtual-function
  • 7/25/2019 OOPS Inteview

    11/11

    %an we specif" the access modifier for e)plicitl" implemented

    interface methodG

    No, we can2t specif" the access modifier for the e)plicitl" implemented interface method. $" default its scope will be internal.

    hat is Protected access modifier in %&G

    The protected !e"word is a member access modifier. (t can onl" be used in a declaring a function or method not in the class ie. a class can2t be declared

    as protected class.

    A protected member is accessible from within the class in which it is declared, and from within an" class derived from the class that declare this member.

    (n other words access is limited to within the class definition and an" class that inherits from the class

    A protected member of a base class is accessible in a derived class onl" if the access ta!es place through the derived class t"pe.

    or more details see http->>msdn.microsoft.com>en*us>librar">bcd=61a8#4./9.asp)

    hat is Public access modifier in %&G

    The public !e"word is an access modifier for t"pes and t"pe members ie. we can declare a class or its member 8functions or methods9 as Public. There

    are no restrictions on accessing public members.

    hat is Private access modifier in %&G

    The private !e"word is a member access modifier ie. we can2t e)plicitl" declare a class as Private, however if do not specif" an" access modifier to theclass, its scope will be assumed as Private. Private access is the least permissive access level of all access modifiers.

    Private members are accessible onl" within the bod" of the class or the struct in which the" are declared. This is the default access modifier for the class

    declaration.

    http://www.dotnetfunda.com/interviews/show/419/can-we-specify-the-access-modifier-for-explicitly-implemented-interfachttp://www.dotnetfunda.com/interviews/show/419/can-we-specify-the-access-modifier-for-explicitly-implemented-interfachttp://www.dotnetfunda.com/interviews/show/420/what-is-protected-access-modifier-in-csharphttp://www.dotnetfunda.com/interviews/show/421/what-is-public-access-modifier-in-csharphttp://www.dotnetfunda.com/interviews/show/422/what-is-private-access-modifier-in-csharphttp://www.dotnetfunda.com/interviews/show/419/can-we-specify-the-access-modifier-for-explicitly-implemented-interfachttp://www.dotnetfunda.com/interviews/show/419/can-we-specify-the-access-modifier-for-explicitly-implemented-interfachttp://www.dotnetfunda.com/interviews/show/420/what-is-protected-access-modifier-in-csharphttp://www.dotnetfunda.com/interviews/show/421/what-is-public-access-modifier-in-csharphttp://www.dotnetfunda.com/interviews/show/422/what-is-private-access-modifier-in-csharp