Content deleted Content added
m →Python: added a missing ":" |
Coding standards |
||
Line 26:
public:
Example();
Example(int a, int b);
};
Example :: Example()
Line 39:
When an object is declared in a parameterized constructor, the initial values have to be passed as arguments to the constructor function. The normal way of object declaration may not work. The constructors can be called explicitly or implicitly. The method of calling the constructor implicitly is also called the ''shorthand'' method.
<source lang="c">
Example e = Example(0, 50);
Example e(0, 50);
</source>
Line 82:
In C++, when constructor is invoked without new the objects are created on stack. When objects are created using new they are created on heap. They must be deleted implicitly by a destructor or explicitly by a call to operator ''delete''.
== Language details ==
=== Java ===
Line 104:
public class Example
{
//
public Example()
{
this(1);
}
//
public Example(int input)
{
data = input; // This is an assignment
}
//
private int data;
}
</source>
<source lang="java">
//
//
Example e = new Example(42);
</source>
Line 158 ⟶ 157:
public class MyClass
{
private int a;
private string b;
//
public MyClass() : this(42, "string")
{
}
//
public MyClass(int a, string b)
{
this.a = a;
this.b = b;
}
}
</source>
<source lang="csharp">
//
//
MyClass c = new MyClass(42, "string");
</source>
Line 192 ⟶ 191:
public class MyClass
{
private static int _A;
//
static MyClass()
{
_A = 32;
}
//
public MyClass()
{
}
}
</source>
<source lang="csharp">
//
//
// right before the instantiation
//
MyClass c = new MyClass();
</source>
Line 263 ⟶ 262:
<source lang="ocaml">
type MyClass(_a : int, _b : string) = class
//
let a = _a
let b = _b
do printfn "a = %i, b = %s" a b
//
new(_a : int) = MyClass(_a, "") then
printfn "Integer parameter given"
Line 281 ⟶ 280:
<source lang = "ocaml">
//
// instantiating an object with the primary constructor
let c1 = new MyClass(42, "string")
// instantiating an object with additional constructors
let c2 = new MyClass(42)
let c3 = new MyClass("string")
Line 296 ⟶ 295:
* Creation procedures have no explicit return type (by definition of ''procedure'').{{Efn|Eiffel ''routines'' are either ''procedures'' or ''functions''. Procedures never have a return type. Functions always have a return type.}}
* Creation procedures are named.
* Creation procedures are designated by name as creation procedures in the text of the class.
* Creation procedures can be explicitly invoked to re-initialize existing objects.
Line 410 ⟶ 409:
# Default attribute values, if you have any.
my %defaults = ( foo => "bar" );
# Initialize attributes as a combination of default values and arguments passed.
my $self = { %defaults, @_ };
Line 473 ⟶ 472:
class Person
{
private $name;
public function __construct($name)
{
$this->name = $name;
}
public function getName()
{
return $this->name;
}
}
</source>
Line 518 ⟶ 517:
<source lang="ruby">
class ExampleClass
end
|