Access modifiers, encapsulation, inheritance

Source: Internet
Author: User

Access modifiers

There are 4 of

Commonly used to have

Public: As long as the namespace is referenced, you can access it freely.

Private: Only within the current class can be accessed

Not used.

Internal: Internal, accessible within the current assembly, the Assembly is the namespace, this modifier is the default

Protected: Protected, the current class and its subclasses are accessible

Namespaces:
Also called an assembly, each folder in the project is a separate namespace
If you want to use a class file under one of the namespaces, you must first reference this namespace

Encapsulation: packing and sealing up;

Example:

private string _code;
public string Code
{
Get
{
return _code;
}
set {_code = value;}
}

Restrictions can be added to the set;

A member variable can have a number of properties

The property return type can be any type, not must be the same as the member variable type

Properties can be read-only or write-only, or they can have both

Inherited:
Subclasses can inherit all public methods and properties of the parent class

The parent class cannot invoke the methods and properties of a subclass, even if the


The subclass can be converted to a parent class, and the converted parent can be converted back to the appropriate subclass.

The subclass is converted to a parent class that cannot be converted to another subclass

Parent class

Subclass-Subclass of a class, derived class, superclass

Access modifiers, encapsulation, inheritance

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.