Inheritance/Single: Difference between revisions

Content added Content deleted
(Added AppleScript example.)
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 200: Line 200:
=={{header|C}}==
=={{header|C}}==
* See [[Inheritance/C]]
* See [[Inheritance/C]]

=={{header|ChucK}}==
<lang ChucK>public class Drums{
//functions go here...
}</lang>
<lang ChucK>public class LatinKit extends Drums{
//functions go here...
}</lang>
<lang ChucK>public class ElectronicKit extends Drums{
//functions go here...
}</lang>
<lang ChucK>public class Congas extends LatinKit{
//functions go here...
}</lang>
<lang ChucK>public class TechnoDrums extends ElectronicKit{
//functions go here...
}</lang>

=={{header|C++}}==
<lang cpp>class Animal
{
// ...
};

class Dog: public Animal
{
// ...
};

class Lab: public Dog
{
// ...
};

class Collie: public Dog
{
// ...
};

class Cat: public Animal
{
// ...
};</lang>


=={{header|C sharp|C#}}==
=={{header|C sharp|C#}}==
Line 273: Line 230:
/* ... */
/* ... */
// ...
// ...
}</lang>

=={{header|C++}}==
<lang cpp>class Animal
{
// ...
};

class Dog: public Animal
{
// ...
};

class Lab: public Dog
{
// ...
};

class Collie: public Dog
{
// ...
};

class Cat: public Animal
{
// ...
};</lang>

=={{header|ChucK}}==
<lang ChucK>public class Drums{
//functions go here...
}</lang>
<lang ChucK>public class LatinKit extends Drums{
//functions go here...
}</lang>
<lang ChucK>public class ElectronicKit extends Drums{
//functions go here...
}</lang>
<lang ChucK>public class Congas extends LatinKit{
//functions go here...
}</lang>
<lang ChucK>public class TechnoDrums extends ElectronicKit{
//functions go here...
}</lang>
}</lang>


Line 631: Line 631:
// ...
// ...
}</lang>
}</lang>

=={{header|F#}}==
The <code>()</code> behind the class names indicates a public default constructor; you need some type of public constructor to derive from a class.
<lang fsharp>type Animal() =
class // explicit syntax needed for empty class
end

type Dog() =
inherit Animal()

type Lab() =
inherit Dog()

type Collie() =
inherit Dog()

type Cat() =
inherit Animal()</lang>


=={{header|Factor}}==
=={{header|Factor}}==
Line 749: Line 767:
' ...
' ...
End Type</lang>
End Type</lang>

=={{header|F#}}==
The <code>()</code> behind the class names indicates a public default constructor; you need some type of public constructor to derive from a class.
<lang fsharp>type Animal() =
class // explicit syntax needed for empty class
end

type Dog() =
inherit Animal()

type Lab() =
inherit Dog()

type Collie() =
inherit Dog()

type Cat() =
inherit Animal()</lang>


=={{header|Go}}==
=={{header|Go}}==
Line 1,151: Line 1,151:
...
...
:- end_object.</lang>
:- end_object.</lang>



=={{header|M2000 Interpreter}}==
=={{header|M2000 Interpreter}}==
Line 1,233: Line 1,232:
var Collie = $new(null);
var Collie = $new(null);
$objsetproto(Collie, Dog);</lang>
$objsetproto(Collie, Dog);</lang>

=={{header|Nemerle}}==
=={{header|Nemerle}}==
<lang nemerle>class Animal {
<lang nemerle>class Animal {
Line 1,447: Line 1,447:
(*functions go here...*)
(*functions go here...*)
end</lang>
end</lang>



=={{header|Oforth}}==
=={{header|Oforth}}==
Line 1,470: Line 1,469:
::class collie subclass dog
::class collie subclass dog
</lang>
</lang>



=={{header|OxygenBasic}}==
=={{header|OxygenBasic}}==
Line 1,586: Line 1,584:
# methods go here...
# methods go here...
}</lang>
}</lang>

=={{header|Perl 6}}==

{{works with|Rakudo|2015-09-16}}
<lang perl6>class Animal {}
class Dog is Animal {}
class Cat is Animal {}
class Lab is Dog {}
class Collie is Dog {}

say Collie.^parents; # undefined type object
say Collie.new.^parents; # instantiated object</lang>
{{out}}
<pre>((Dog) (Animal))
((Dog) (Animal))</pre>

The <tt>.^parents</tt> notation indicates a method call to the object's metaobject rather than to the object itself.


=={{header|Phix}}==
=={{header|Phix}}==
Line 1,821: Line 1,802:
(check-false (is-a? (new collie%) cat%))
(check-false (is-a? (new collie%) cat%))
</lang>
</lang>

=={{header|Raku}}==
(formerly Perl 6)

{{works with|Rakudo|2015-09-16}}
<lang perl6>class Animal {}
class Dog is Animal {}
class Cat is Animal {}
class Lab is Dog {}
class Collie is Dog {}

say Collie.^parents; # undefined type object
say Collie.new.^parents; # instantiated object</lang>
{{out}}
<pre>((Dog) (Animal))
((Dog) (Animal))</pre>

The <tt>.^parents</tt> notation indicates a method call to the object's metaobject rather than to the object itself.


=={{header|REBOL}}==
=={{header|REBOL}}==
Line 1,950: Line 1,949:
<lang self>lab = (| parent* = dog |)</lang>
<lang self>lab = (| parent* = dog |)</lang>
<lang self>collie = (| parent* = dog |)</lang>
<lang self>collie = (| parent* = dog |)</lang>



=={{header|Sidef}}==
=={{header|Sidef}}==