A class foo is described with the class statement:
A class can contain variables and zero or more constructors , which are called when an object of this class is generated:
class foo
{
int a = 0;
this()
{
a++;
}
this(int b)
{
a = b;
}
}
foo myFoo = new foo(); foo myFoo2 = new foo(5);
|
Every class can have none ore one SuperClass, from which it is inherited from. It's constructor ("this()") can use super to call the SuperClasses constructor:
class bar:foo {
bool isnumber;
this() {
isnumber = false;
super(-1);
}
this(int b) {
super(b+1);
isnumber = true;
}
}
bar myBar = new bar(); bar myBar2 = new bar(8);
|
In this case, SuperClass is foo, the class name is bar and the constructor of foo is called with -1 or with b+1.
|