c++ Free Job Alerts

download c++ Free Job Alerts

of 5

Transcript of c++ Free Job Alerts

  • 8/13/2019 c++ Free Job Alerts

    1/5

    1. What is a class?Ans:The objects with the same data structure (attributes) and behavior (operations) are called class.

    2. What is an object?Ans:It is an entity which may correspond to real-world entities such as students, employees, bankaccount. It may be concrete such as file system or conceptual such as scheduling policies inmultiprocessor operating system.

    very object will have data structures called attributes and behavior called operations.3. What is the difference between an object and a class?Ans:!ll objects possessing similar properties are grouped into class.Example :person is a class, ram, hari are objects of person class. !ll have similar attributes like name,age, se" and similar operations like speak, walk.

    #lass person$private%char name&'*int age*char se"*public% speak()*walk()*

    +*4. What is the difference between class and strctre?Ans:In class the data members by default are private but in structure they are by default public

    !. "efine object based pro#rammin# lan#a#e?Ans:bject based programming language support encapsulation and object identity without supportingsome important features of s language.bject based languagencapsulation / object Identity

    $. "efine object oriented lan#a#e?Ans:bject-oriented language incorporates all the features of object based programming languagesalong with inheritance and polymorphism.Example:0 c//, java.

    %. "efine &&'s?Ans: is a method of implementation in which programs are organi1ed as co-operative collection of

    objects, each of which represents an instance of some class and whose classes are all member of ahierarchy of classes united through the property of inheritance.

    (. What is pblic) protected) and pri*ate?Ans:These are access specifier or a visibility lebels .The class member that has been declared asprivate can be accessed only from within the class. ublic members can be accessed from outside theclass also. 2ithin the class or from the object of a class protected access limit is same as that of privatebut it plays a prominent role in case of inheritance

    +. What is a scope resoltion operator?Ans:The scope resolution operator permits a program to reference an identifier in the global scope thathas been hidden by another identifier with the same name in the local scope.

    1,. What do -o mean b- inheritance?Ans:The mechanism of deriving a new class (derived) from an old class (base class) is calledinheritance. It allows the e"tension and reuse of e"isting code without having to rewrite the code from

    scratch.11. What is abstraction?Ans:The techni3ue of creating user-defined data types, having the properties of built-in data types and aset of permitted operators that are well suited to the application to be programmed is known as dataabstraction. #lass is a construct for abstract data types (!4T).

    12. What is encapslation?Ans:It is the mechanism that wraps the data and function it manipulates into single unit and keeps it safefrom e"ternal interference.

  • 8/13/2019 c++ Free Job Alerts

    2/5

  • 8/13/2019 c++ Free Job Alerts

    3/5

    24. What do -o mean b- *irtal methods?Ans:virtual methods are used to use the polymorphism feature in #//. 6ay class ! is inherited fromclass @. If we declare say function f() as virtual in class @ and override the same function in class ! thenat runtime appropriate method of the class will be called depending upon the type of the object.

    2!. What do -o mean b- static methods?Ans:@y using the static method there is no need creating an object of that class to use that method. 2e

    can directly call that method on that class. Aor e"ample, say class ! has static function f(), then we cancall f() function as !.f(). There is no need of creating an object of class !.

    2$. ow man- wa-s are there to initiali8e an int with a constant?Ans:Two.There are two formats for initiali1ers in #// as shown in the e"ample that follows. The first format usesthe traditional # notation. The second format uses constructor notation.int foo B'C*int bar (B'C)*

    2%. What is a constrctor?Ans:#onstructor is a special member function of a class, which is invoked automatically whenever aninstance of the class is created. It has the same name as its class.

    2(. What is destrctor?Ans:4estructor is a special member function of a class, which is invoked automatically whenever an

    object goes out of the scope. It has the same name as its class with a tilde character prefi"ed.2+. What is an explicit constrctor?Ans:! conversion constructor declared with the e"plicit keyword. The compiler does not use an e"plicitconstructor to implement an implied conversion of types. ItDs purpose is reserved e"plicitly forconstruction.

    3, What is the 9tandard emplate 5ibrar-?Ans:! library of container templates approved by the !=6I committee for inclusion in the standard #//specification. ! programmer who then launches into a discussion of the generic programming model,iterators, allocators, algorithms, and such, has a higher than average understanding of the newtechnology that 6T: brings to #// programming.

    31. What problem does the namespace featre sol*e?

    Ans:9ultiple providers of libraries might use common global identifiers causing a name collision when anapplication tries to link with two or more such libraries. The namespace feature surrounds a libraryDse"ternal declarations with a uni3ue namespace that eliminates the potential for those collisions. Thissolution assumes that two library vendors donDt use the same namespace identifier, of course.

    32. What is the se of ;sin#< declaration?Ans:! using declaration makes it possible to use a name from a namespace

    33. What is a template?Ans:Templates allow us to create generic functions that admit any data type as parameters and return avalue without having to overload the function with all the possible data types. >ntil certain point they fulfillthe functionality of a macro. Its prototype is any of the two following ones%template functionEdeclaration*template functionEdeclaration*

    34. "ifferentiate between a template class and class template?

    Ans:emplate class:

    ! generic definition or a parameteri1ed class not instantiated until the client provides the neededinformation. ItDs jargon for plain templates.6lass template:

    ! class template specifies how individual classes can be constructed much like the way a class specifieshow individual objects can be constructed. ItDs jargon for plain classes.

    3!. What is the difference between a cop- constrctor and an o*erloaded assi#nment operator?Ans:! copy constructor constructs a new object by using the content of the argument object. !n

  • 8/13/2019 c++ Free Job Alerts

    4/5

    overloaded assignment operator assigns the contents of an e"isting object to another e"isting object ofthe same class.

    3$. What is a *irtal destrctor?Ans:The simple answer is that a virtual destructor is one that is declared with the virtual attribute.

    3%. What is an incomplete t-pe?Ans:Incomplete type refers to pointers in which there is non availability of the implementation of the

    referenced location or it points to some location whose value is not available for modification.Example:int FiGH i points to address HFi* set the value of memory location pointed by i.Incomplete types are otherwise called uninitiali1ed pointers.

    3(. What do -o mean b- 9tac0 nwindin#?Ans:It is a process during e"ception handling when the destructor is called for all local objects betweenthe place where the e"ception was thrown and where it is caught.

    3+. What is a container class? What are the t-pes of container classes?Ans:! container class is a class that is used to hold objects in memory or e"ternal storage. ! containerclass acts as a generic holder. ! container class has a predefined behavior and a well-known interface. !container class is a supporting class whose purpose is to hide the topology used for maintaining the list ofobjects in memory. 2hen a container class contains a group of mi"ed objects, the container is called a

    heterogeneous container* when the container is holding a group of objects that are all the same, thecontainer is called a homogeneous container

    4,. ame some pre object oriented lan#a#es?Ans:6malltalk, ?ava, iffel, 6ather.

    41. ame the operators that cannot be o*erloaded?Ans:si1eof, ., .F, .-J, %%, K%

    42. What is an adaptor class or Wrapper class?Ans:! class that has no functionality of its own. Its member functions hide the use of a third partysoftware component or an object with the non-compatible interface or a non-object-orientedimplementation.

    43. What is a ll object?Ans:It is an object of some class whose purpose is to indicate that a real object of that class does note"ist. ne common use for a null object is a return value from a member function that is supposed to

    return an object with some specified properties but cannot find such an object.44. What is class in*ariant?Ans:! class invariant is a condition that defines all valid states for an object. It is a logical condition toensure the correct working of a class. #lass invariants must hold when an object is created, and theymust be preserved under all operations of the class. In particular all class invariants are bothpreconditions and post-conditions for all operations or member functions of the class.

    4!. What is a dan#lin# pointer?Ans:! dangling pointer arises when you use the address of an object after its lifetime is over. This mayoccur in situations like returning addresses of the automatic variables from a function or using the addressof the memory block after it is freed. "ample% The following code snippet shows this%class 6ample$public%

    int Fptr*6ample(int i)$ptr new int(i)*+L6ample()$delete ptr*+void rint5al()

  • 8/13/2019 c++ Free Job Alerts

    5/5

    $cout MM ;The value is < MM Fptr*++*void 6omeAunc(6ample ")$cout MM ;6ay i am in someAunc < MM endl*+int main()$6ample sB B*6omeAunc(sB)*sB.rint5al()*+In the above e"ample when rint5al() function is called it is called by the pointer that has been freed bythe destructor in 6omeAunc.

    4$. "ifferentiate between the messa#e and method?Ans:=essa#e:bjects communicate by sending messages to each other.

    ! message is sent to invoke a method.=ethodrovides response to a message and it is an implementation of an operation

    4%. ow can we access protected and pri*ate members of a class?Ans:In the case of members protected and private, these could not be accessed from outside the sameclass at which they are declared. This rule can be transgressed with the use of the friend keyword in aclass, so we can allow an e"ternal function to gain access to the protected and private members of aclass.

    4(. 6an -o handle exception in 6//?Ans:Nes we can handle e"ception in #// using keyword% try, catch and throw. rogram statements thatwe want to monitor for e"ceptions are contained in a try block. If an e"ception occurs within the try block,it is thrown (using throw).The e"ception is caught, using catch, and processed.

    4+. What is *irtal fnction?Ans:! virtual function is a member function that is declared within a base class andredefined by a derived class .To create a virtual function, the function declaration in the base class ispreceded by the keyword virtual.

    !,. What do -o mean b- earl- bindin#?Ans:arly binding refers to the events that occur at compile time. arly binding occurs whenall information needed to call a function is known at compile time. "amples of early binding includenormal function calls, overloaded function calls, and overloaded operators. The advantage of earlybinding is efficiency.

    !1. What do -o mean b- late bindin#?Ans::ate binding refers to function calls that are not resolved until run time. 5irtual functions are used toachieve late binding. 2hen access is via a base pointer or reference, the virtual function actually called isdetermined by the type of object pointed to by the pointer.