Describe an abstract class and explain when one might be useful.

1 Answer

Answer :

An abstract class is a class that cannot be instantiated but must be inherited. It can contain both implemented methods and abstract methods, which must be implemented in an inheriting class. Thus, it can define common functionality for some methods, a common interface for other methods, and leave more detailed implementation up to the inheriting class.

Related questions

Description : What’s the difference between an interface and abstract class?

Last Answer : Answer: An abstract class and Interface both have method only but not have body of method.The difference between Abstract class and An Interface is that if u call Ablstract class then u have to call ... type, Parameter type, Parameter Number all must be same . Only body of method can change. 

Description : When do you absolutely have to declare a class as abstract?

Last Answer : 1. When the class itself is inherited from an abstract class, but not all base abstract methods have been overridden. 2. When at least one of the methods in the class is abstract.

Description : What’s an abstract class?

Last Answer : Answer:Classes that cannot be instantiated. We cannot create an object from such a class for use in our program. We can use an abstract class as a base class, creating new classes that will inherit from ... can inherit from a non-abstract class. In C++, this concept is known as pure virtual method.

Description : Write some code using interfaces, virtual methods, and an abstract class.

Last Answer : using System; public interface Iexample1 { int MyMethod1(); } public interface Iexample2 { int MyMethod2(); } public abstract class ABSExample : Iexample1, Iexample2 { public ABSExample( ... override void VIRTMethod2() { System.Console.WriteLine("VIRTMethod2 has been overridden"); } }

Description : When do you absolutely have to declare a class as abstract?

Last Answer : 1. When the class itself is inherited from an abstract class, but not all base abstract methods have been overridden. 2. When at least one of the methods in the class is abstract.

Description : What’s an abstract class?

Last Answer : A class that cannot be instantiated. An abstract class is a class that must be inherited and have the methods overridden. An abstract class is essentially a blueprint for a class without any implementation.

Description : When do you absolutely have to declare a class as abstract (as opposed to free-willed educated choice or decision based on UML diagram)?

Last Answer : When at least one of the methods in the class is abstract. When the class itself is inherited from an abstract class, but not all base abstract methods have been overridden.

Description : What’s an abstract class? 

Last Answer : A class that cannot be instantiated. A concept in C++ known as pure virtual method. A class that must be inherited and have the methods over-ridden. Essentially, it’s a blueprint for a class without any implementation.

Description : Define what are the features of abstract class?

Last Answer : 1. An abstract class cannot be instantiated, and it is an error to use the new operator on an abstract class. 2. An abstract class is permitted (but not required) to contain abstract methods and accessors. 3. An abstract class cannot be scaled.

Description : Describe XCOPY deployment. Under what conditions is it useful? When can it not be used?

Last Answer : XCOPY deployment is a simple method of deployment where the DOS command XCOPY is used to copy the application directory and any subdirectories to the target machine. You can use XCOPY ... an application requires a more complex deployment or references shared assemblies, you cannot use XCOPY.

Description : Can abstract methods override virtual methods? 

Last Answer : Yes

Description : Define what is the difference between an abstract method & virtual method?

Last Answer : An Abstract method does not provide an implementation and forces overriding to the deriving class (unless the deriving class also an abstract class), whereas the virtual method has an ... abstract method does not provide implementation & forces the derived class to override the method.

Description : Define what is the use of the abstract keyword?

Last Answer : The modifier abstract is a keyword used with a class, to indicate that this class cannot itself have direct instances or objects, and it is intended to be only a ‘base’ class to other classes.

Description : Briefly describe how a class is similar to a structure. How are they different?

Last Answer : Both classes and structures can have members such as methods, properties, and fields, both use a constructor for initialization, and both inherit from System.Object. Both classes and structures can be ... are value types, and the memory that holds structure instances is allocated on the stack. 

Description : Explain why you might use enums and constants instead of their associated literal values.

Last Answer : Enums and constants make code easier to read and maintain by substituting human-legible tokens for frequently used constant values.

Description : Explain when you might implement a shortcut menu instead of a main menu.

Last Answer : If every possible option is exposed on a main menu, the menu can become busy and hard to use. Shortcut menus allow less frequently used options to be exposed only in situations where they are likely to be used.

Description : What is method overloading, and when is it useful?

Last Answer : Method overloading allows you to create several methods with the same name but different signatures. Overloading is useful when you want to provide the same or similar functionality to different sets of parameters.

Description : What is a delegate useful for?

Last Answer : The main reason we use delegates is for use in event driven programming. 

Description : Explain sealed class in C#?

Last Answer : A sealed class is used to prevent the class from being inherited from other classes. So “sealed” modifier also can be used with methods to avoid the methods to override in the child classes.

Description : Explain what constructors and destructors are and describe what they are used for.

Last Answer : The constructor is the method that initializes a class or structure and is run when a type is first instantiated. It is used to set default values and perform other tasks required by the class. ... reclaimed by garbage collection. It contains any code that is required for cleanup of the object. 

Description : Do you need to instantiate a class before accessing a Shared (static) member? Why or why not?

Last Answer : Because a Shared (static) member belongs to the type rather than to any instance of the type, you can access the member without first creating an instance of the type.

Description : How do you enable your application to use .NET base class library members without referencing their fully qualified names?

Last Answer : Use the Imports keyword (Visual Basic .NET) or the using keyword (Visual C#) to make a .NET Framework namespace visible to your application. 

Description : what is Class ?

Last Answer : Answer:A group of objects that share a common definition and that therefore share common properties, operations, and behavior. A user-defined type that is defined with the class-key 'class,' 'struct, ... one class to be an expansion of another, and classes can restrict access to their members. 

Description : How do you specify a custom attribute for the entire assembly (rather than for a class) ?

Last Answer : Answer: Global attributes must appear after any top-level using clauses and before the first type or namespace declarations. An example of this is as follows: using System; [assembly : ... that in an IDE-created project, by convention, these attributes are placed in AssemblyInfo.cs.

Description : What is the role of the DataReader class in ADO.NET connections?

Last Answer : It returns a read-only, forward-only rowset from the data source. A DataReader provides fast access when a forward-only sequential read is needed.

Description : What’s the difference between the Debug class and Trace class? 

Last Answer : Documentation looks the same. Use Debug class for debug builds, use Trace class for both debug and release builds.

Description : If a base class has a number of overloaded constructors, and an inheriting class has a number of overloaded constructors; can you enforce a call from an inherited constructor to a specific base constructor?

Last Answer : Yes, just place a colon, and then keyword base (parameter list to invoke the appropriate constructor) in the overloaded constructor definition inside the inherited class.

Description : What’s the implicit name of the parameter that gets passed into the set method/property of a class?

Last Answer : Value. The data type of the value parameter is defined by whatever data type the property is declared as.

Description : What is the difference between a Struct and a Class? 

Last Answer : Structs are value-type variables and are thus saved on the stack, additional overhead but faster retrieval. Another difference is that structs cannot inherit.

Description : What is an interface class?

Last Answer : Interfaces, like classes, define a set of properties, methods, and events. But unlike classes, interfaces do not provide implementation. They are implemented by classes, and defined as separate entities from classes. 

Description : Can you allow a class to be inherited, but prevent the method from being over-ridden?

Last Answer : Yes. Just leave the class public and make the method sealed. 

Description : Can you prevent your class from being inherited by another class?

Last Answer : Yes. The keyword “sealed” will prevent the class from being inherited. 

Description : What is the syntax to inherit from a class in C#? 

Last Answer : Place a colon and then the name of the base class. Example: class MyNewClass : MyBaseClass

Description : What class is underneath the SortedList class?

Last Answer : A sorted HashTable. 

Description : What’s the .NET collection class that allows an element to be accessed using a unique key? 

Last Answer : HashTable. 

Description : What’s the top .NET class that everything is derived from?

Last Answer : System.Object.

Description : Are private class-level variables inherited? 

Last Answer : Yes, but they are not accessible. Although they are not visible or accessible via the class interface, they are inherited.

Description : Who is a protected class-level variable available to?

Last Answer : It is available to any sub-class (a class inheriting this class). 

Description : In terms of constructors, what is the difference between: public MyDerived() : base() an public MyDerived() in a child class?

Last Answer : Nothing

Description : How do you refer to a member in the base class?

Last Answer : To refer to a member in the base class use:return base.NameOfMethod(). 

Description : What is a nested class?

Last Answer : A class declare within a class. 

Description : Can properties hide base class members of the same name?

Last Answer : Yes

Description : Write some code for a custom collection class.

Last Answer : using System; using System.Collections; public class Items : IEnumerable { private string[] contents; public Items(string[] contents) { this.contents = contents; } public IEnumerator GetEnumerator() { ... (string item in items) { Console.WriteLine(item); } Console.ReadLine(); } }

Description : A class can have many mains, how does this work? 

Last Answer : Only one of them is run, that is the one marked (public) static, e.g: public static void Main(string[] args) { // // TODO: Add code to start application here // } private void Main(string[] args, int i) { }

Description : Class methods to should be marked with what keyword?

Last Answer : static

Description : What is the default accessibility for a class?

Last Answer : internal for a top level class, private for a nested one. 

Description : What is the role of the DataReader class in ADO.NET connections?

Last Answer : It returns a read-only, forward-only rowset from the data source. A DataReader provides fast access when a forward-only sequential read is needed. 

Description : What’s the difference between the Debug class and Trace class? 

Last Answer : Documentation looks the same. Use Debug class for debug builds, use Trace class for both debug and release builds.

Description : If a base class has a number of overloaded constructors, and an inheriting class has a number of overloaded constructors; can you enforce a call from an inherited constructor to a specific base constructor?

Last Answer : Yes, just place a colon, and then keyword base (parameter list to invoke the appropriate constructor) in the overloaded constructor definition inside the inherited class.

Description : What’s the implicit name of the parameter that gets passed into the set method/property of a class?

Last Answer : Value. The data type of the value parameter is defined by whatever data type the property is declared as.