Question of the Day
How do you designate a method as Abstract?
|
Answers from January 13, 2007 - Question of the Day
What is the visibility of a member declared as public?
Public designation allows a member to be accessed by the member methods
of other classes.
|
Answers from January 6, 2007 - Question of the Day
Should you wrap unboxing operations in a try block?
Typically, you will wrap an unbox operation in a try block. If
the object being unboxed is null or a reference to an object of a
different type, then an InvalidCastException is thrown.
|
Answers from December 26, 2006 - Question of the Day
Where are reference types kept?
Reference types are kept on the heap.
|
Answers from December 18, 2006 - Question of the Day
How do you unbox an object?
You accomplish unboxing an object in 2 steps.
-
Make sure the object instance is a boxed value of the given value type.
-
Copy the value from the instance to the value-type value.
The object being unboxed must be of the appropriate type for the assigned
variable.
|
Answers from December 17, 2006 - Question of the Day
Where are value types kept?
Value types such as integers are kept on the stack.
|
Answers from July 8, 2006 - Question of the Day
What does making one or more methods of a class abstract force the class
to be?
Making one or more methods of any class abstract has the side effect of
making the class abstract.
|
Answers from June 29, 2006 - Question of the Day
Does an abstract method have an implementation?
An abstract method has no implementation. It creates a method name and
signature that must be implemented in all derived classes.
|
Answers from June 28, 2006 - Question of the Day
Is unboxing an explicit or implicit conversion?
To return the boxed object back to a value type, you must explicitly
unbox it.
|
Answers from June 27, 2006 - Question of the Day
What is boxing and unboxing in the C# language?
Boxing and unboxing are the processes that enable value types
(e.g., integers) to be treated as reference types (objects). The value
is boxed inside an object, and subquently unboxed back to
a value type.
|
Answers from June 26, 2006 - Question of the Day
How is Polymorphism implemented in a method of a base class?
To create a method that supports polymorphism, you need only mark
it as virtual in its base class.
public virtual void SupportPoly()
|
Answers from June 21, 2006 - Question of the Day
How can you restrict the visibility of a class and its members?
You can restrict the visibility of a class and its members through the use of access
modifiers, such as: private, public, protected, internal and internal
protected.
|
Answers from June 20, 2006 - Question of the Day
When the keyword new appears in code, what should it do?
When the keyword new appears in code, it should document the versioning of
code. It points a potential client to the base class to see what you aren't overriding.
Using new scattershot undermines this documentation. Further, the warning
exists to help identify a real issue.
|
Answers from June 13, 2006 - Question of the Day
What is the root of all classes?
All C# classes, of any type, are treated as if they ultimately derive from System.Object.
This includes value types.
Previous Questions of the Day
|
Answers from June 12, 2006 - Question of the Day
What keyword can you use to require subclasses to implement a method of
their base?
To require subclasses to implement a method of their base, you need to
designate that method as abstract in the base class.
|
Answers from June 9, 2006 - Question of the Day
How does the keyword override help to prevent breaking existing code in
derived classes?
In C#, a virtual function is always considered to be the root of virtual
dispatch. Once C# finds a virtual method, it looks no further up
the inheritance hierarchy.
|
Answers from June 8, 2006 - Question of the Day
What is a sealed class?
A sealed class doesn't allow classes to derive from it at all. Placed
before the class declaration, the sealed keyword precludes derivation.
Classes are most often marked sealed to prevent accidental inheritance.
|
Answers from June 7, 2006 - Question of the Day
Is it okay to instantiate an object of an abstract class?
Abstract classes establish a base for derived classes,but it is not legal
to instantiate an object of an abstract class.
Once you declare a method to be abstract, you prohibit the creation of any instances
of that class.
|
Answers from June 6, 2006 - Question of the Day
If a base class has an accessible default constructor, is the derived
constructor required to invoke the base constructor?
No, if a base class has an accessible default constructor, the derived
constructor is not required to invoke the base constructor explicitly. The
default constructor is called implicitly.
|
Answers from June 5, 2006 - Question of the Day
What is the visibility of a member declared as internal?
The keyword internal extends visibility to methods of any class in the same
assembly (DLL).
|
Answers from June 1, 2006 - Question of the Day
If a base class of a derived class does not have a default constructor; what
must the derived constructor do?
If the base class does not have a default constructor, every derived
constructor must explicitly invoke one of the base class constructors
using the base keyword.
|
Answers from May 31, 2006 - Question of the Day
How is polymorphism implemented in a method of a base class?
Simply override the base class virtual method by using the keyword override
in the derived class method definition and add the new code for the overridden
method.
public override void BaseMethod(){}
|
Answers from May 30, 2006 - Question of the Day
How does a derived class invoke the constructor of its parent class (ListBox)?
The derived class constructor invokes the constructor of its parent by placing
a colon (:) after the parameter list and then invoking the base class with the
keyword base.
public ListBox( int top, int left) : base ( parentTop, parentLeft )
|