OOPS page3 | Sample Papers

Samplepaperz.blogspot.com

Samplepaperz.blogspot.com
Home » » OOPS page3

OOPS page3

Written By Blogger on 25 August 2013 | 00:39


  • Whats the Difference between Interface and Abstract Class?

Abstract Class:
Have constructors.
Not necessarily for the class inheriting it to Implement all the Methods.
Doesn't Support Multiple Inheritance.
Where everything is Opposite in the Interfaces.
What can you do to make class available for inheritance but you need to prevent its method to come in inheritance chain?
Well, Declare a class with public access specifier and mark all it's method to sealed . As anything which is declared with sealed keyword cannot be inherited.
  • What Are Attributes in DotNet?

An Attribute is a declarative tag which can be used to provide information to the compiler about the behaviour of the C# elements such as classes and assemblies.
C# provides convenient technique that will handle tasks such as performing compile time operations , changing the behaviour of a method at runtime or maybe even handle unmanaged code.
C# Provides many Built-in Attributes
Some Popular ones are
- Obsolete
- DllImport
- Conditional
- WebMethod
and Many more.
Members please keep on posting more responses providing more In-Built attributes.
Regards Hefin Dsouza
  • What is Polymorphism?

In OPPS, polymorphism(Greek meaning is 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 virtualmethods(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
is 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. 
  • 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 internaly.
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.
  • 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 doesnt 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.
  • 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.


For more OOPS Interview Questions and answers DOWNLOAD PDF from here.











25 Aug 2013 Albert Augustine

0 comments:

Post a Comment

Search