.


:




:

































 

 

 

 


]




, , , .

, , , Delphi, C++ Java. :

( TVehicle);

. Delphi overload, , override reintroduce .

type TVehicle = class constructor Create; virtual; end; TAutomobile = class (TVehicle) constructor Create; override; end; TMotorcycle = class (TVehicle) constructor Create; override; end; TMoped = class (TMotorcycle) // - Create constructor Create(x: integer); reintroduce; end;

. , TVehicle.

type CVehicle = class of TVehicle;

, TVehicle.

var cv: CVehicle; v: TVehicle; cv:= TAutomobile;v:= cv.Create;

,

cv:= TMoped;v:= cv.Create;

reintroduce , TMotorcycle.Create ( , , !)

. ( )

]

[]++

. , .

class ClassWithConstructor { public: /* */ ClassWithConstructor(float parameter): object(parameter) {} /* AnotherClass(float); */ private: AnotherClass object;};

]Python

Python __init__. , self.

]

class ClassWithConstructor: def __init__(self): """This method is constructor.""" pass

]Delphi

Delphi, C++, constructor. , Create.

]

TClassWithConstructor = class public constructor Create; end;

]Java

Java:

;

( new);

synchronized, final, abstract, native static ;

.

]

public class Example { // public Example() { this (1); } // public Example(int input) { data = input; } private int data;} // , Example e = new Example(42);

]JavaScript

JavaScript , new. this.

]

function Example(initValue) { this. myValue = initValue;} Example.prototype.getMyValue = function () { return this. myValue; } // , var exampleObject = new Example(120);

]Visual Basic.NET

Visual Basic.NET New.

]

Class Foobar Private strData As String ' Constructor Public Sub New(ByVal someParam As String) strData = someParam End SubEnd Class ' ' Dim foo As New Foobar(".NET")

[]C#

]

class myClass{ private int mA; private string mB; public myClass(int a, string b) { mA = a; mB = b; }} // , myClass c = new myClass(42, "string");

]

, , . - - . :

( [ 1]).

( );

;

( ) ;

( , ) ( ) ;

, [ 2].

[ 3], x: T, create x.make :

T[ 4];

make ;

x.

]

POINT. make feature.

create , . default_create, , ANY, make POINT.

class POINT create default_create, make feature make (a_x_value: REAL; a_y_value: REAL) do x:= a_x_value y:= a_y_value end x: REAL -- X y: REAL -- Y...

, POINT, my_point_1 my_point_2 POINT.

my_point_1 (0.0; 0.0). , default_create, ANY. create my_point_1.default_create. , ( create).

my_point_2, my_point_2.

make - , my_point_2, .

my_point_1: POINT my_point_2: POINT... create my_point_1 create my_point_2.make (3.0, 4.0) my_point_2.make (5.0, 8.0)...

]ColdFusion

]

, ColdFusion -. ColdFusion 'init', .

< cfcomponent displayname="Cheese"> <!--- ---> < cfset variables.cheeseName = "" /> <!--- ---> < cffunction name="init" returntype="Cheese"> < cfargument name="cheeseName" type="string" required="true" /> < cfset variables.cheeseName = arguments.cheeseName /> < cfreturn this /> </ cffunction ></ cfcomponent >

]PHP

]

PHP ( 5) __construct(), new . , , . , , new, .

class Person{ private $name; function __construct($name) { $this->name = $name; } function getName() { return $this->name; }}

, PHP 4 ( ) .

class Person{ private $name; function Person($name) { $this->name = $name; } function getName() { return $this->name; }}

[] ( )

. ( ) , , - . . ( , ) . :

class Student { // //... ...}

, Student () . () . , , , ( ) . ( ). ,

class Student { Student (String studentName, String Address, int ID) { //... ... } //...}

 

[]





:


: 2016-12-17; !; : 521 |


:

:

, ,
==> ...

1515 - | 1496 -


© 2015-2024 lektsii.org - -

: 0.019 .