What is the default accessibility for a class?

1 Answer

Answer :

internal for a top level class, private for a nested one. 

Related questions

Description : What is the default accessibility for members of a struct? 

Last Answer : private

Description : What is the default accessibility for members of an interface?

Last Answer : public

Description : Briefly describe the five accessibility requirements of the Certified for Windows logo program.

Last Answer : The five requirements are o Support standard system settings. This requires your application to be able to conform to system settings for colors, fonts, and other UI elements. o Be ... information by sound alone. This requirement can be met by providing redundant means of conveying information.

Description : Why can’t you specify the accessibility modifier for methods inside the interface?

Last Answer : They all must be public, and are therefore public by default. 

Description : Describe the accessibility modifier “protected internal”. 

Last Answer : It is available to classes that are within the same assembly and derived from the specified base class.

Description : Can nested classes use any of the 5 types of accessibility?

Last Answer : Yes

Description : What is private accessibility?

Last Answer : Access is restricted to within the containing class. 

Description : What is protected internal accessibility?

Last Answer : Access is restricted to types derived from the containing class or from files within the same assembly.

Description : What is internal accessibility?

Last Answer : A member marked internal is only accessible from files within the same assembly.

Description : What is protected accessibility? 

Last Answer : Access is restricted to types derived from the containing class. 

Description : What is public accessibility?

Last Answer : There are no access restrictions. 

Description : Why can’t you specify the accessibility modifier for methods inside the interface?

Last Answer : They all must be public, and are therefore public by default.

Description : Describe the accessibility modifier “protected internal”. 

Last Answer : It is available to classes that are within the same assembly and derived from the specified base class.

Description : Why can’t you specify the accessibility modifier for methods inside the interface? 

Last Answer : They all must be public. Therefore, to prevent you from getting the false impression that you have any freedom of choice, you are not allowed to specify any accessibility, it’s public by default.

Description : Describe the accessibility modifier protected internal. 

Last Answer : It’s available to derived classes and classes within the same Assembly (and naturally from the base class it’s declared in). 

Description : What is the default index of an array? 

Last Answer : 0

Description : What is the default value for a bool? 

Last Answer : false

Description : If I have a constructor with a parameter, do I need to explicitly create a default constructor?

Last Answer : Yes

Description : C# provides a default constructor for me. I write a constructor that takes a string as a parameter, but want to keep the no parameter one. How many constructors should I write? 

Last Answer : Two. Once you write at least one constructor, C# cancels the freebie constructor, and now you have to write one yourself, even if there’s no implementation in it.

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

Last 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. ... common interface for other methods, and leave more detailed implementation up to the inheriting class.

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 : 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’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 : 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 : 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 : 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 : 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 : Class methods to should be marked with what keyword?

Last Answer : static