Object-oriented programming (OOPs) Interview Questions and Answers

OOP Questions and Answers:

1 :: Can we call a base class method without creating instance?

Yep. But ..

► Its possible If its a static method.

► Its possible by inheriting from that class also.

► Its possible from derived classes using base keyword.
4.4/5 Rating (5 votes)
Is This Answer Correct?    13 Yes 0 No
Place Your Answer

2 :: In which cases you use override and new base?

Use the new modifier to explicitly hide a member inherited from a base class. To hide an inherited member, declare it in the derived class using the same name, and modify it with the new modifier.
3/5 Rating (2 votes)
Is This Answer Correct?    5 Yes 2 No
Place Your Answer

3 :: What is a private constructor? Where will you use it?

When you declare a Constructor with Private access modifier then it is called Private Constructor. We can use the private constructor in singleton pattern.

If you declare a Constructor as private then it doesn’t allow to create object for its derived class, i.e you loose inherent facility for that class.

Example:

Class A

{

// some code

Private Void A()

{

//Private Constructor

}

}



Class B:A

{

//code

}



B obj = new B();// will give Compilation Error



Because Class A constructor declared as private hence its accessibility limit is to that class only, Class B can't access. When we create an object for Class B that constructor will call constructor A but class B have no rights to access the Class A constructor hence we will get compilation error.
4/5 Rating (1 vote)
Is This Answer Correct?    7 Yes 0 No
Place Your Answer

4 :: Can we declare private class in a Namespace?

No. If you try to create a private class in a Namespace, Compiler will throw a compile time error “Namespace elements cannot be explicitly declared as private, protected, or protected internal”.

Reason: The message says it all. Classes can only be declared as private, protected or protected internal when declared as nested classes, other than that, it doesn't make sense to declare a class with a visibility that makes it unusable, even in the same module. Top level classes cannot be private, they are "internal" by default, and you can just make them public to make them visible from outside your DLL.
4/5 Rating (1 vote)
Is This Answer Correct?    7 Yes 0 No
Place Your Answer

5 :: What is Polymorphism?

In OPP’S, polymorphism(Greek meaning “having multiple forms”) is the ablity of being able to assign a different meaning or usage to something in different contexts - specifically, to allow an entity such as a a function, or an object to have more than one forms.

In C# :
Parent classes may define and implement “virtual” methods(Which is done using the “virtual” keyword), and derived classes can override them(using the “override” keyword), which means they provide their own definition and implementation.At run-time, when user’s code calls the method, the CLR looks up the run-time type of the object, and invokes that override of the virtual method. Thus in your source code when a method of the base class is called it executes the overriden method.
2/5 Rating (1 vote)
Is This Answer Correct?    6 Yes 1 No
Place Your Answer

Rate This Category:
4/5 Rating (1 vote)
Place Your Question



Top: Object-oriented programming (OOPs) Interview Questions and Answers
Object-oriented programming (OOPs) Interview Questions and Answers

Top Frequently Asked OOP Question
Frequently Asked OOP Job Interview Question


Top Frequently opened Computer Programming Job Interview categories
Most popular Computer Programming Job Interview categories

Comments About Object-oriented programming (OOPs) Interview Questions and Answers

Share your valuable opinions, ideas and suggestions about Object-oriented programming (OOPs) Interview Questions and Answers
While placing your comment your email address is required but won't be published any where else; Personal information will be kept confidential; we do not sell or release our respective visitors private information.
  1. Webmaster 22nd of May 2012

    Webmaster Said

    Tell us what you feel about Object-oriented programming (OOPs) Interview Questions and Answers
    All comments will be published after review. No login or registration is required to post a comment on Object-oriented programming (OOPs) Interview Questions and Answers We offer and invite you to submit your valuable comment now; Please be respectful of others when commenting. Insulting others, self-promotional comments, website promotional comments, marketing stuff, SEO Techniques, SMS-style content and off-topic comments will not be approved at this information portal.
    So start sharing your thoughts regarding Object-oriented programming (OOPs) Interview Questions and Answers
    Thank you.

  2. baig (1 Comment) 16th of September 2011

    baig Said

    nice information

Leave a Comment

Leave a Comment
  1.  Enter This Verification Code  Regenerate Verification Code  



Your reply will be added to the comment above (Below any other replies to this comment) -

Top Comments About: Object-oriented programming (OOPs) Interview Questions and Answers
Comments on Object-oriented programming (OOPs) Interview Questions and Answers

 
Top of Link batk to Object-oriented programming (OOPs) Interview Questions and Answers
Link batk to Object-oriented programming (OOPs) Interview Questions and Answers