C # simple interview questions (1)

Source: Internet
Author: User

1. Briefly describe the access permissions of private, protected, public, and internal modifiers.

PRIVATE: a private member that can be accessed within the class.

Protected: protects members, which can be accessed within the class and in the inheritance class.

Public: A Public member. It is completely public and has no access restrictions.

Internal: InSameProgramCan be accessed in the set. ---- @, thank you Bo you

2. Will Private Members be inherited?

Yes, but cannot be accessed. So it seems that they cannot be inherited, but they are actually inherited.

3. C # does it support multiple inheritance? Not supported, but can be implemented using interfaces.

4. What is the common base class of all objects in C? Using M. object.

5. What is object-oriented?

Everything is an object. Its main features include encapsulation, inheritance, and polymorphism.

6. How to Implement Polymorphism

1. When you call a member function directly through an object, the member function of the class of the object is always used by default (unless you use: to display the specified class name)

2. when you call a member function by pointing to an object pointer or referencing it, if the function is a real function, call the pointer or the referenced class member function. If the function is a virtual function, then, call the pointer or reference the member functions of the class of the object to which it points.

7. What is packing and unpacking?

The conversion from the value type interface to the reference type is boxed. Convert from the reference type to the value type to The binning.

Boxing is to convert the value type to the reference type, int I = 3; object o = I; this is the packing process.

Unboxing converts the reference data to the value type, Int J = (INT) O;

8. What is interface? What is the difference between it and abstract class?

Interfaces are used to define behavioral norms without specific implementations. abstract classes can be partially implemented in addition to defining behavioral norms, but a class can implement multiple interfaces, but only one parent class can be inherited.

9. When to use abstract classes and interfaces

Interfaces are used for standardization, and abstract classes are used for commonality. Only methods, attributes, events, and indexers can be declared in the interface. Abstract classes can be implemented using methods or non-static class variables. Abstract classes are classes, so they can only be inherited by a single object, but multiple interfaces can be implemented at a time. Abstract Some implementations that can provide some methods, but interfaces cannot. An example of an abstract class is given by its subclass. An interface instance is provided by the class that implements the interface. If a method is used in an abstract class, its subclass has this method at the same time. When a new method is added to an interface, the class implementing it must be rewritten (that is why the interface is a Class Specification ). Interface members are defined as public, abstract class members can also be private, protected, internal, or protected internal members (the protected internal members can onlyCodeOr in a derived class ).

In addition, the interface cannot contain fields, constructors, destructor, static members, or constants.

11. What is an abstract class )?

A class that cannot be instantiated. Abstract classes generally contain abstract methods. Of course, they can also be implemented. An inherited class can be instantiated only when abstract methods of all abstract classes are implemented.

12. When must a class be declared as an abstract class?

When this class contains abstract methods, or the class does not fully implement the abstract methods of the parent class.

13. Why cannot I specify the modifier of methods in the interface?

The methods in the interface are used to define the contract for communication between objects. It is meaningless to specify the methods in the interface as private or protected. They are common methods by default.

14. What if there are repeated method names in the interface?

In this case, you can decide how to implement it. Of course, you must be very careful. However, there is no problem in the compilation process.

15. C # What are the similarities and differences between interfaces and classes.

Differences:

The interface cannot be instantiated directly.

The interface does not contain the implementation of methods.

Interfaces, classes, and structures can be inherited from multiple interfaces. However, C # only supports single inheritance: the class can only be inherited from one base class.

Class definition can be split between different source files.

Same:

Interfaces, classes, and structures can be inherited from multiple interfaces.

An interface is similar to an abstract base class: any non-Abstract type that inherits an interface must implement all the members of the interface.

Interfaces can contain events, indexers, methods, and attributes.

A class can implement multiple interfaces.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.