区委书记什么级别| a1是什么| 榴莲补什么| 幼儿睡觉出汗多是什么原因| 吃芒果后不能吃什么| 熳是什么意思| 梦到离婚是什么征兆| 肺结核传染途径是什么| dr股票是什么意思| hpv是什么病严重吗| 典韦字什么| 什么是犯太岁| 真菌感染是什么| 人类的祖先是什么动物| 什么时候可以上环最好的| 美容美体是干什么的| 绿色属于五行属什么| 生米煮成熟饭是什么意思| 氯是什么| 晚上梦见蛇是什么预兆| 走路脚后跟疼是什么原因| 为什么会甲状腺肿大| 脸发红发烫是什么原因| 杜甫的诗被称为什么| 飞蓬草有什么功效| 雪莲果什么季节成熟| 什么的问题| 咳嗽能吃什么食物| 三个犬念什么字| 成人发烧吃什么退烧药| 芡实是什么| 上海手表什么档次| 扶她是什么意思| dtc什么意思| hl什么意思| 黑色水笔是什么笔| 尿潜血1十是什么原因| 血糖低吃什么药| 猛虎下山是什么生肖| 手指头发麻是什么原因| 血糖偏高能吃什么水果和食物最好| 儿童咳嗽吃什么药管用| 9月19号什么星座| 喝冰糖水有什么好处和坏处| 血液凝固快是什么原因| 韩愈字什么| 什么人不适合做业务员| 什么药补肾壮阳| 冒汗是什么原因| 口腔溃疡吃什么药好| 复检是什么意思| 女生喜欢男生什么行为| 中央型肺ca是什么意思| 商字五行属什么| 胸口中间疼挂什么科| 甲炎是什么病| 车水马龙什么意思| 孕妇梦见自己出轨是什么意思| 麻雀吃什么| 垫底是什么意思| 甘露醇是什么| 胡汉三回来了什么意思| 心衰挂什么科| 90年属马的是什么命| 女人左下巴有痣代表什么| 茉莉茶叶属于什么茶| 卷帘大将是干什么的| 肛门是什么意思| 龙的九个儿子都叫什么名字| 纸醉金迷下一句是什么| 大腿抽筋是什么原因引起的| 碰到蛇是什么征兆| 阴道里面有个肉球是什么| 用盐刷牙有什么好处和坏处| 肾上腺是什么| 间质性肺炎是什么意思| 立秋日有什么禁忌| 癌胚抗原是什么| 肢体拘挛是什么意思| 月经过后腰酸疼是什么原因| 高考四百分左右能上什么学校| 为什么长痘| 收缩压和舒张压是什么意思| 西游记是什么时候写的| 花枝招展是什么意思| 疑难杂症是什么意思| 孕妇肾积水是什么原因引起的| 智齿长什么样子| 柳树像什么| 逝者如斯夫什么意思| 颈椎压迫神经挂什么科| 草莓像什么| 潘多拉是什么意思| 吃什么能降低尿蛋白| 肠道功能紊乱吃什么药| 谈情说爱是什么意思| 吃什么提高免疫力最快| 糖粉和白糖有什么区别| 吃饭容易出汗是什么原因| 睡觉咬牙是什么原因| 木耳炒什么好吃| 婚检检查什么项目| 什么水果含维生素b| 掐是什么意思| 儒家思想的核心是什么| 狮子座什么性格| 倒数是什么| 牛肉可以炖什么| 大姨妈推迟什么原因| 多吃山竹有什么好处| 属龙什么命| 舌苔开裂是什么原因呢| 桑葚和枸杞泡水喝有什么好处| 纳采是什么意思| 宇宙的中心是什么| ber是什么意思| 四个金念什么| 7月26日什么星座| 人参片泡水喝有什么功效和作用| 猫咪喜欢吃什么| 转归是什么意思| 肋间神经痛挂什么科| 王羲之的儿子叫什么名字| 重庆五行属什么| 王者风范是什么意思| 河马吃什么| 8月29号是什么日子| 腿上有白点是什么原因| 深渊是什么意思| 锡纸什么牌子的好| 白凉粉是什么东西| 把你的心我的心串一串是什么歌| 汗蒸有什么好处和功效| 仓鼠可以吃什么水果| 3ph是什么意思| 欲盖弥彰什么意思| 五行中金代表什么| 蒙脱石散是什么药| 小产吃什么好恢复营养| 反绒皮是什么材质| 电解质水是什么水| 小鹿乱撞是什么意思| 鸡拉绿色粪便吃什么药| 唇裂是什么原因造成的| 怨念是什么意思| 统招是什么意思| 二月十九是什么星座| tpa是什么意思| 什么情况需要割包皮| 双肺结节是什么病| 梅毒吃什么药好得快| 碧玺五行属什么| 脸容易红是什么原因| 维生素b3又叫什么| 溴隐亭是什么药| 备皮是什么意思| 提肛有什么好处| 木薯粉是什么做的| 10月4号是什么星座| 老上火是什么原因造成的| 旭日阳刚为什么不火了| 慢性宫颈炎是什么意思| 吃什么不容易怀孕| 老年人骨质疏松吃什么钙片好| 黄体破裂是什么| 硝苯地平是什么药| 检查乙肝挂什么科| 纪委是做什么的| 吃什么降血脂| 正常白带是什么颜色| 小便有点红是什么原因| 神龛是什么意思| hermes是什么意思| 槟榔长什么样| 心悸心慌是什么原因| 感冒吃什么恢复快| 什么是双一流| 聪明如你什么意思| 吃什么白蛋白提升快| 莯字五行属什么| 万花筒是什么| 火龙果有什么营养| 马拉车是什么牌子的包| 休克的本质是什么| 圣字五行属什么| 精神出轨什么意思| 宫缩是什么感觉| 去脂肪粒最有效的药膏叫什么| 吃什么能提高血压| 只欠东风的上一句是什么| 舌头有点麻是什么病的前兆| 男人出虚汗是什么原因引起的| 眼白发青是什么原因| 大便一粒粒是什么原因| 白子是什么| 重庆什么时候解放的| 缝纫机油是什么油| dpa是什么意思| 追什么| 什么是修养| 清热去火吃什么药| bl是什么单位| 时光荏苒是什么意思| 刘欢属什么生肖| 突然勃不起来是什么原因| 腹部ct能检查出什么| 京东积分有什么用| 女人的网名叫什么好听| 什么程度要做肾穿刺| inv是什么意思| 平衡液又叫什么名字| 托班是什么意思| 什么是自限性疾病| 皮蛋不能和什么一起吃| 女命带驿马是什么意思| 血脂高吃什么油好| 尿肌酐低说明什么| 假卵是什么样子的| 打招呼是什么意思| 女金片的功效与作用是什么| 忽然流鼻血是什么原因引起的| 湿气太重吃什么排湿最快| 眼底充血用什么眼药水| 菜场附近开什么店好| cpi是什么意思啊| 向日葵什么时候采摘| 睡眠时间短早醒是什么原因| 风麻疹是什么引起的| 李世民字什么| 停胎是什么原因造成的| dyf是什么意思| 尼哥是什么意思| 大肠杆菌属于什么菌| 工字可以加什么偏旁| 小暑节气吃什么| hrd阳性是什么意思| 七叶子是什么意思| 腋下副乳有什么危害吗| 为什么呀| 日本是什么时候侵略中国的| 东四命是什么意思| 重日是什么意思| 移徒是什么意思| 螨虫是什么| 明朝后面是什么朝代| 表姐的女儿叫什么| 怀孕一个月有点见红是什么情况| ur品牌属于什么档次| 肾脏不好吃什么食物好| 不一样的烟火什么意思| 医共体是什么意思| 吃什么对牙齿好| 肾结石可以喝什么饮料| 1974年属什么生肖| 蜂胶是什么东西| 奕五行属性是什么| 什么会导致铅中毒| 内衣什么品牌最好| 皮肤过敏挂什么科| kiv是什么意思| 乐高可以拼什么| 朱字五行属什么| 千焦是什么单位| 肝病吃什么好得快| 百度Lompat ke isi

2017年4月自学考试《毛泽东思想概论》答案(网友

Ti Wikipédia Sunda, énsiklopédi bébas
Révisi per 19 Maret 2017 05.54 ku Ilhambot (obrolan | kontribusi) (Ngarapihkeun éjahan, replaced: meter → méter (2), model → modél (2))
(béda) ← Révisi leuwih heubeul | Témbongkeun révisi kiwari (béda) | Révisi nu leuwih anyar → (béda)
百度 各民主党派和无党派人士的政治合作,扩大了整合的边界和张力,进一步强化了中国政党制度的整合功能,使中国政党制度成为有着强大动员力、决策力、执行力和凝聚力的制度。

Dina object-oriented programming (OOP), classes digunakeun keur ngelompokkeun variabel jeung fungsi nu patali. Class ngébréhkeun kumpulan variabel instance nu diéekapsulasi sarta méthode (fungsi), mungkin ogé ku jalan nerapkeun tipe éta babarengan jeung fungsi nu ngawangun nu bisa digunakeun keur nyieun objék class.

Artikel ieu keur dikeureuyeuh, ditarjamahkeun tina basa Inggris.
Bantuanna didagoan pikeun narjamahkeun.

Class mangrupa pakét kohésif nu eusina jenis husus métadata compile-time. Dina kelas aya aturan-aturan nu ngajelaskeun kalakuan objects; Objek-objek ieu ngacu ka "instance" ti kelas eta. A class specifies the structure of data which éach instance contains as well as the methods (functions) which manipulate the data of the object and perform tasks; such methods are sometimes described as "behavior". A method is a function with a special property that it has access to data stored in an object. A class is the most specific type of an object in relation to a specific layer. A class may also have a representation (metaobject) at run-time, which provides run-time support for manipulating the class-related metadata.

Instances of a class will have certain aspects (aka: féatures, attributes or properties) in common. A class 'Person' for example would describe the properties common to all instances of the 'Person' class. One of the benefits of programming with classes is that all instances of a particular class will follow the defined behaviour of the class they instantiate. éach person is generally alike; but varies in such properties as "height" and "weight". The class would list types of such instance variables; and also define, via methods, the actions which humans can perform: "run", "jump", "sleep", "throw object", etc.

Antarbeungeut

[édit | édit sumber]

A class can "implement" (or "realize") multiple interfaces, éach of which specify one or more abstract method signatures (name and type of the method and its paraméters) which must be defined (overridden) in that class.

Unlike multiple inheritance where actual code is inherited (along with naming and logical conflicts) interfacing allows to define a behaviour-interface (methods) all implementing classes should be able to fulfill. Partial implementations of interfaces are not allowed, that is, every specified method has to have an implementation. However some languages do not require that every paraméter combination needs to be supported.

éach interface of the class is associated with a type of object references referring to the interface, through which methods of objects can be invoked. éach reference points to a single instance of the class. éach reference has a lifetime, which specifies how long the reference can be used, usually bound to the time when some specific operations are invoked via the interface. It is assumed that there is a mechanism for accessing the object with a valid object reference. However, while the object reference is a reference to a specific location at any one time, over time the same object can be located at different places.

The object-oriented programming methodology is designed in such a way that the operations of any interface of a class are usually chosen to be independent of éach other. This méans that an interface places no requirements for clients to invoke the operations of one interface in any particular order. This approach has the benefit that client code can rely that the operations of an interface are available for use whenever the client holds a valid reference to the object. This will also result in a client-server (or layered) design where servers do not depend in any way on the clients.

The methods that are not in any of the interfaces of a class are private to the class, and not intended to be depended on by other classes.

The "set of all interfaces of a class" is sometimes called the interface of the class.

The internal data structures defined as part of a class are not considered to be part of its interface. Rather, public accessor methods can be used to inspect or alter object data. The various object-oriented programming languages enforce this to various degrees. For example, Java does not allow the programmer to access the private data of a class at all, wheréas in languages like Objective-C or Perl the programmer can do what they want. In C++, private methods are visible but not accessible in the interface; however they are commonly made invisible by explicitly declaring fully abstract classes that represent the interfaces of the class.

Struktur class

[édit | édit sumber]
UML notation for classes

A class contains a description of structure of data ("state") stored in the objects of the class. The state of an object is stored in some resource, such as memory or a file. The storage is assumed to be located in a specific location, such that it is possible to access the object via references to the identity of the objects. However, the actual storage location associated with an object may change with time. In such situations, the identity of the object does not change. The state is encapsulated and every access to the state occurs via methods of the class. Specific data items in the state, such as xsize and ysize in the example, are sometimes called class attributes or class properties.

A class implements its interfaces by specifying methods that describe what operations can be performed on the data stored in the objects of the class. éach method specifies only tasks that are related to the stored data. Multimethods can be used when a single task requires access to many objects' data.

A class also describes a set of invariants that are preserved by every method in the class. An invariant is a constraint on the state of an object that should be satisfied by every object of the class. The main purpose of the invariants is to establish what objects belong to the class. An invariant is what distinguishes datatypes and classes from éach other, that is, a class does not allow use of all possible values for the state of the object, only those that are well-defined by the semantics of the intended use of the datatype. The set of supported methods often implicitly establishes an invariant. Some programming languages support specification of invariants as part of the definition of the class, and enforce them via the type system. Encapsulation of state is necessary for being able to enforce the invariants of the class.

An implementation of a class specifies constructor and destructor functions that allow création and destruction of objects of the class. A constructor that takes arguments can be used to créate an object from data. The main purpose of a constructor is to establish the invariant of the class, failing if the invariant isn't valid. The main purpose of a destructor is to destroy the identity of the object, invalidating any references in the process. A destructor that returns a value can be used to obtain a public representation (transfer encoding) of an object of a class and simultanéously destroy the copy of the object stored in current thréad's memory [If supported by the programming language used]. Constructors and destructors are also sometimes used to reserve and reléase resources associated with the object.

A class can also implement a set of auxiliary functions, sometimes called class functions or static methods. Static methods are often used to find, créate or destroy objects of the class. Constructors and destructors are sometimes specified as static methods. Often, mechanisms for sending an object to another location or changing the class of an object are specified as static methods.

The class members can be designated as public, private or protected. The public access specifier méans that all clients can access the member by its name. The private access specifier restricts the access to the class itself. The protected access specifier allows the class itself and all its subclasses to access the member. In addition, some languages, such as C++, support a mechanism where a function explicitly declared as friend of the class may access the members designated as private or protected. Access specifiers do not control visibility, in that even private members may be visible to client code. An inaccessible but visible member may be referred to at run-time (e.g. pointer to it can be returned from member functions), but all attempts to use it by referring to the name of the member from client code will be prevented by the type checker. Object-oriented design uses the access specifiers in conjunction with careful design of public method implementations to enforce class invariants. Access specifiers are intended to protect against accidental use of members by clients, but are not suitable for run-time protection of object's data. [1]

Asosiasi antar class

[édit | édit sumber]

In object-oriented design an association between two classes is a type of a link between the corresponding objects. A (two-way) association between classes A and B describes a relationship between éach object of class A and some objects of class B, and vice versa. Associations are often named with a verb, such as "subscribes-to".

An association role describes the role of an instance of a class when the instance participates in an association. An association role is related to éach end of the association. The role describes an instance of a class from the point of view of a situation in which the instance participates in the association. For example, a "subscriber" role describes instances of the class "Person" when it participates in a "subscribes-to" relationship with the class "Magazine". Also, a "Magazine" has the "subscribed magazine" role when the subscribers subscribe-to it.

Association role multiplicity describes how many instances correspond to éach instance of the other class(es) of the association. Common multiplicities are "0..1", "1..1", "1..*" and "0..*", where the "*" specifies any number of instances.

There are some special kinds of associations between classes. Composition between class A and class B describes a "part-of" relationship where instances of class B have shorter lifetime than the lifetime of the corresponding instances of the enclosing class. Class B is said to be a part of class A. This is often implemented in programming languages by allocating the data storage of instances of class A to contain a representation of instances of class B. Aggregation is like composition in that it describes that instances of a class are part of instances of the other class, but the constraint on lifetime of the instances is not required. The implementation of aggregation is often via a pointer or reference to the contained instance. In both cases, method implementations of the enclosing class can invoke methods of the part class.

Class lokal

[édit | édit sumber]

When a class is declared inside a function it is called a local class. It has some unique properties like it can use global as well as static variables of the function declared before the class but can't access automatic variables. Global variables should be used with scope(::) operator.

There are some restriction on its use they can't have static data members and member functions must be defined inside the class only enclosing fuction can't access private members of the class but they can be made to do so by declaring them Friend to that local class.

Class sabagian

[édit | édit sumber]
 Artikel utama: Partial classes.

Partial classes are classes that can be split over multiple files, making it éasier to déal with large quantities of code. At compile time the partial classes are grouped together, thus logically maké no difference to the output. An example of the use of partial classes may be the separation of user interface logic and processing logic. A primary benefit of partial classes is allowing different programmers to work on different parts of the same class at the same time. They also maké automatically generated code éasier to interpret, as it is separated from other code into a partial class. Partial classes have been around in SmallTalk under the name of Class Extensions for considerable time. In pre-beta versions of Visual Studio 2005 the partial keyword was known as "expands" in Visual Basic. With the arrival of the .NET framework 2 Microsoft then introduced partial classes (see partial types), supported in both C# 2.0 and Visual Basic 2005.

Subclass jeung superclass

[édit | édit sumber]

Classes are often related in some way. The most popular of these relations is inheritance, which involves subclasses and superclasses, also known respectively as child classes (or derived classes) and parent classes (or base classes). If [car] was a class, then [Jaguar] and [Porsche] might be two sub-classes. If [Button] is a subclass of [Control], then all buttons are controls. Subclasses usually consists of several kinds of modifications (customizations) to their respective superclasses: addition of new instance variables, addition of new methods and overriding of existing methods to support the new instance variables.

Conceptually, a superclass should be considered as a common part of its subclasses. This factoring of commonality is one mechanism for providing reuse. Thus, extending a superclass by modifying the existing class is also likely to narrow its applicability in various situations. In Object-oriented design, careful balance between applicability and functionality of superclasses should be considered. Subclassing is different from subtyping in that subtyping déals with common behaviour wheréas subclassing is concerned with common structure.

Some programming languages (for example C++) allow multiple inheritance—they allow a child class to have more than one parent class. This technique has been criticized by some for its unnecessary complexity and being difficult to implement efficiently, though some projects have certainly benefited from its use. Java, for example has no multiple inheritance, as its designers felt that it would add unnecessary complexity.

Sub- and superclasses are considered to exist within a hierarchy defined by the inheritance relationship. If multiple inheritance is allowed, this hierarchy is a directed acyclic graph (or DAG for short), otherwise it is a tree. The hierarchy has classes as nodes and inheritance relationships as links. The levels of this hierarchy are called layers or levels of abstraction. Classes in the same level are more likely to be associated than classes in different levels.

There are two slightly different points of view as to whether subclasses of the same class are required to be disjoint. Sometimes, subclasses of a particular class are considered to be completely disjoint. That is, every instance of a class has exactly one most-derived class, which is a subclass of every class that the instance has. This view does not allow dynamic change of object's class, as objects are assumed to be créated with a fixed most-derived class. The basis for not allowing changes to object's class is that the class is a compile-time type, which does not usually change at runtime, and polymorphism is utilised for any dynamic change to the object's behaviour, so this ability is not necessary. And design that does not need to perform changes to object's type will be more robust and éasy-to-use from the point of view of the users of the class.

From another point of view, subclasses are not required to be disjoint. Then there is no concept of a most-derived class, and all types in the inheritance hierarchy that are types of the instance are considered to be equally types of the instance. This view is based on a dynamic classification of objects, such that an object may change its class at runtime. Then object's class is considered to be its current structure, but changes to it are allowed. The basis for allowing object's class to change is performance. It's more efficient to allow changes to object's type, since references to the existing instances do not need to be replaced with references to new instances when the class of the object changes. However, this ability is not réadily available in all programming languages. The performance analysis depends on the proposition that dynamic changes to object structure are common. This may or may not be the case in practice.

Alesan-alesan pikeun nerapkeun class

[édit | édit sumber]

Classes, when used properly, can accelerate development by reducing redundant code entry, testing and bug fixing. If a class has been thoroughly tested and is known to be a solid work, it stands to réason that implementing that class or extending it will reduce if not eliminate the possibility of bugs propagating into the code. In the case of extension new code is being added so it also requires the same level of testing before it can be considered solid.

Another réason for using classes is to simplify the relationships of interrelated data. Rather than writing code to repéatedly draw a GUI window on the terminal screen, it is simpler to represent the window as an object and tell it to draw itself as necessary. With classes, GUI items that are similar to windows (such as dialog boxes) can simply inherit most of their functionality and data structures from the window class. The programmer then need only add code to the dialog class that is unique to its operation. Indeed, GUIs are a very common and useful application of classes, and GUI programming is generally much éasier with a good class framework.

Kategori class

[édit | édit sumber]

Abstract and concrete classes

[édit | édit sumber]

An abstract class, or abstract base class (ABC), is one that is designed only as a parent class and from which child classes may be derived, and which is not itself suitable for instantiation. Abstract classes are often used to represent abstract concepts or entities. The incomplete féatures of the abstract class are then shared by a group of sibling sub-classes which add different variations of the missing pieces. In C++, an abstract class is defined as a class having at léast one pure virtual method, i.e., an abstract method, which may or may not possess an implementation.

Abstract classes are superclasses which contain abstract methods and are defined such that concrete subclasses are to extend them by implementing the methods. The behaviors defined by such a class are "generic" and much of the class will be undefined and unimplemented. Before a class derived from an abstract class can be instantiated, it must implement particular methods for all the abstract methods of its parent classes.

In computing, when specifying an abstract class, the programmer is referring to a class which has elements that are méant to be implemented by inheritance. The abstraction of the class methods to be implemented by the sub-classes is méant to simplify software development.

A concrete class, however, is a class for which entities (instances) may be créated. This contrasts with abstract classes which can not be instantiated because it deféats its purpose of being an 'abstract'.

Most object oriented programming languages allow the programmer to specify which classes are considered abstract and will not allow these to be instantiated (in Java, for example, the keyword abstract is used). This also enables the programmer to focus on planning and design. The actual implementation of course is to be done in the derived classes.

In C++, an abstract class is a class having at léast one pure virtual function. They can not be instantiated and will generate an error if an attempt is made. They are méant to function as stubs, allowing the programmer to identify what modules of functions (behaviour or methods) are needed without having to actually implement them. This is in line with OOP's philosophy of allowing the programmer to concentrate on how an object should behave without going into the actual detail.

Metaclasses

[édit | édit sumber]

Metaclasses are classes whose instances are classes. A metaclass describes a common structure of a collection of classes. A metaclass can implement a design pattern or describe a shorthand for particular kinds of classes. Metaclasses are often used to describe frameworks.

In some languages such as Smalltalk and Ruby, a class is also an object; thus éach class is an instance of the unique metaclass, which is built in the language. For example, in Objective-C, éach object and class is an instance of NSObject. CLOS (Common Lisp Object System) provides metaobject protocols (MOP) to implement those classes and metaclasses.

Non-class-based programming

[édit | édit sumber]

To the surprise of some familiar with the use of classes in OOP, it has been shown that one can design fully fledged object-oriented languages that do not have builtin supports of classes. Those languages are usually designed with the motive to address the problem of tight-coupling between implementations and interfaces due to the use of classes. For example, the Self language was designed to show that the role of a class can be substituted by using an extant object which serves as a prototype to a new object, and the resulting language is as expressive as Smalltalk with more generality in créating objects. See class-based OOP for the criticism of class-based programming and object-based languages for such non-class-based languages.

Run-time representation of classes

[édit | édit sumber]

As a datatype, a class is usually considered as a compile-time construct. A language may also support prototype or factory metaobjects that represent run-time information about classes, or even represent metadata that provides access to reflection facilities and ability to manipulate data structure formats at run-time. Many languages distinguish this kind of run-time type information about classes from a class on the basis that the information is not needed at run-time. Some dynamic languages do not maké strict distinctions between run-time and compile-time constructs, and therefore may not distinguish between metaobjects and classes.

For example: if humans is a metaobject representing the class Person, then instances of class Person can be créated by using the facilities of the human metaobject.

Class without inheritance

[édit | édit sumber]

Not every language that both supports objects and classes is generally seen as object-oriented. Examples are éarlier versions of Visual Basic, which lack the support for inheritance. The lack of inheritance severely impairs the full practice of object-oriented programming. Those languages, sometimes called "object-based languages", do not provide the structural benefits of statically type checked interfaces for objects. This is because in object-based languages it is possible to use and extend data structures and attach methods to them at run-time. This precludes the compiler or interpreter from being able to check the type information specified in the source code as the type is built dynamically and not defined statically. Most of these languages allow for instance behaviour and complex operational polymorphism (see dynamic dispatch and polymorphism).

Instantiation

[édit | édit sumber]

As explained above, classes can be used to créate new objects by instantiating them. In most languages, the structures as defined by the class determine how the memory used by its instances will be laid out. This technique is known as the cookie-cutter model.

The alternative to the cookie-cutter modél is that of for instance Python, where objects are structured as associative key-value containers. In such modéls, objects that are instances of the same class could contain different instance variables, as state can be dynamically added to the object. This may resemble Prototype-based languages in some ways, but it is not equivalent.

Conto 1

[édit | édit sumber]
   #include <iostréam>
   #include <string>
 
   class Hello
   {
       std::string what;

       public:
           Hello(const char* s)
               : what(s)
           {
           }

           void say()
           {
               std::cout << "Hello " << what << "!" << std::endl;
           }
   };

   int main( int argc, char** argv )
   {
       Hello* hello_world = new Hello("world");
       hello_world->say();

       return 0;
   }

This example shows how to define a C++ class named "Hello". It has a private string attribute named "what", and a public method named "say".

Conto 2

[édit | édit sumber]
class Abstract
{
public:
     virtual void MyVirtualMethod() = 0;
};

class Concrete : public Abstract
{
public:
     void MyVirtualMethod()
     {
      //do something
     }
};

An object of class Abstract can not be créated because the function MyVirtualMethod has not been defined (the =0 is C++ syntax for a pure virtual function, a function that must be part of any derived concrete class but is not defined in the abstract base class. The Concrete class is a concrete class because its functions (in this case, only one function) have been declared and implemented.

Conto 3

[édit | édit sumber]
#include <string>
using std::string;

class InetMessage
{
  string m_subject, m_to, m_from;

public:
  InetMessage (const string& subject,
               const string& to,
               const string& from);
  string subject () const;
  string to () const;
  string from () const;
};

Conto 1

[édit | édit sumber]
public class Example1
{
  // This is a Java class, it automatically extends the class Object
}

This example shows the simplest Java class possible.

Conto 2

[édit | édit sumber]
public class Example2 extends Example1
{
  // This is a class that extends the class créated in Example 1.
  protected int data;

  public Example2()
  {
     // This is a constructor for the class.  It does not have a return type.
     data = 1;
  }

  public int getData()
  {
    return data;
  }

  public void setData(int d)
  {
    data = d;
  }
}

This example shows a class that has a defined constructor, one member data, and two accessor methods for that member data. It extends the previous example's class. Note that in Java all classes automatically extend the class Object. This allows you to write generic code to déal with objects of any type.

Conto 1

[édit | édit sumber]
Class Hello
  Private Dim what as String

  Sub Constructor( s as String )
     what = s
  End Sub

  Sub Say()
     MsgBox "Hello " + what + EndOfLine
  End Sub
End Class

Sub App.Open()
   dim h as new Hello( "Foobar" )
   h.Say
End Sub

This example is a port of the C++ example above. It demonstrates how to maké a class named Hello with a private property named what. It also demonstrates the proper use of a constructor, and has a public method named Say. It also demonstrates how to instansiate the class and call the Say method.

Conto 1

[édit | édit sumber]
<?php
class A
{
   function foo()
   {
       if (isset($this)) {
           echo '$this is defined (';
           echo get_class($this);
           echo ")\n";
       } else {
           echo "\$this is not defined.\n";
       }
   }
}

$a = new A();
$a->foo();
?> 

Tempo ogé

[édit | édit sumber]

Literatur

[édit | édit sumber]
左舌根疼痛是什么情况 摔伤用什么药好得快 身份证前六位代表什么 小孩晚上睡觉发梦癫什么原因 猫爪草有什么功效
一库一库雅蠛蝶是什么意思 狗能吃巧克力吗为什么 两个人背靠背是什么牌子 割礼是什么意思 透明质酸是什么
抗hbc阳性是什么意思 九寨沟什么时候去最好 杜甫被后人称为什么 庙会是什么意思 莲雾是什么水果
安踏高端品牌叫什么 核心是什么意思 鼎是干什么用的 为什么气血不足 耳鸣是什么原因引起的嗡嗡的响
乖巧是什么意思hcv8jop1ns0r.cn 有什么聚会玩的游戏hcv8jop5ns9r.cn 尿液检查能查出什么病hebeidezhi.com society是什么意思hcv7jop6ns2r.cn 处男是什么hcv8jop0ns9r.cn
壬午是什么生肖hcv8jop8ns7r.cn 隐翅虫咬到擦什么药膏hcv7jop9ns8r.cn 芦荟有什么作用hcv9jop3ns8r.cn 非农业户口是什么意思hcv8jop8ns3r.cn 十二月六号是什么星座bfb118.com
头发五行属什么inbungee.com 吃什么可以缓解焦虑hcv7jop4ns6r.cn 办理残疾证需要什么材料1949doufunao.com 得了幽门螺旋杆菌有什么症状hcv8jop3ns4r.cn 肠梗阻挂什么科cj623037.com
讲义气是什么意思hcv9jop3ns4r.cn 科举制什么时候废除dajiketang.com 鬼冢虎为什么很少人穿xinjiangjialails.com 妗是什么意思hcv8jop1ns1r.cn 气血不足吃什么hcv7jop7ns1r.cn
百度