Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
7
Task/Inheritance-Single/00-META.yaml
Normal file
7
Task/Inheritance-Single/00-META.yaml
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
category:
|
||||
- Object oriented
|
||||
- Type System
|
||||
- Encyclopedia
|
||||
from: http://rosettacode.org/wiki/Inheritance/Single
|
||||
note: Basic language learning
|
||||
60
Task/Inheritance-Single/00-TASK.txt
Normal file
60
Task/Inheritance-Single/00-TASK.txt
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
::: ''This task is about derived types; for implementation inheritance, see [[Polymorphism]].
|
||||
|
||||
|
||||
Inheritance is an operation of [[type algebra]] that creates a new type from one or several parent types.
|
||||
|
||||
The obtained type is called '''derived type'''.
|
||||
|
||||
It inherits some of the properties of its parent types.
|
||||
|
||||
Usually inherited properties are:
|
||||
:::* methods
|
||||
:::* components
|
||||
:::* parts of the representation
|
||||
|
||||
|
||||
The [[classes | class]] of the new type is a '''subclass''' of the classes rooted in the parent types.
|
||||
|
||||
When all (in certain sense) properties of the parents are preserved by the derived type, it is said to be a [[wp:Liskov_substitution_principle|Liskov subtype]].
|
||||
|
||||
When properties are preserved then the derived type is ''substitutable'' for its parents in all contexts. Usually full substitutability is achievable only in some contexts.
|
||||
|
||||
|
||||
Inheritance is
|
||||
:::* '''single''', when only one parent is allowed
|
||||
:::* '''[[multiple inheritance | multiple]]''', otherwise
|
||||
|
||||
|
||||
Some single inheritance languages usually allow multiple inheritance for certain [[abstract type]]s, interfaces in particular.
|
||||
|
||||
Inheritance can be considered as a relation parent-child.
|
||||
|
||||
Parent types are sometimes called '''supertype''', the derived ones are '''subtype'''. This relation is [[wp:Transitive_relation|transitive]] and [[wp:Reflexive_relation|reflexive]].
|
||||
|
||||
Types bound by the relation form a [[wp:Directed_acyclic_graph directed acyclic graph]] (ignoring reflexivity).
|
||||
|
||||
With single inheritance it becomes a [[wp:Tree_(graph_theory)|tree]].
|
||||
|
||||
|
||||
;Task:
|
||||
Show a tree of types which inherit from each other.
|
||||
::: At the top of the tree should be a class called '''Animal'''.
|
||||
::: The second level should have '''Dog''' and '''Cat'''.
|
||||
::: Under '''Dog''' should be '''Lab''' and '''Collie'''.
|
||||
::: None of the classes need to have any functions, the only thing they need to do is inherit from the specified superclasses <br> (overriding functions should be shown in [[Polymorphism]]).
|
||||
|
||||
|
||||
The tree should look like this:
|
||||
<pre>
|
||||
Animal
|
||||
/\
|
||||
/ \
|
||||
/ \
|
||||
Dog Cat
|
||||
/\
|
||||
/ \
|
||||
/ \
|
||||
Lab Collie
|
||||
</pre>
|
||||
<br><br>
|
||||
|
||||
15
Task/Inheritance-Single/11l/inheritance-single.11l
Normal file
15
Task/Inheritance-Single/11l/inheritance-single.11l
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
T Animal
|
||||
{
|
||||
}
|
||||
T Dog(Animal)
|
||||
{
|
||||
}
|
||||
T Cat(Animal)
|
||||
{
|
||||
}
|
||||
T Lab(Dog)
|
||||
{
|
||||
}
|
||||
T Collie(Dog)
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
public class Animal {
|
||||
// ...
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
public class Cat extends Animal {
|
||||
// ...
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
public class Dog extends Animal {
|
||||
// ...
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
public class Lab extends Dog {
|
||||
// ...
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
public class Collie extends Dog {
|
||||
// ...
|
||||
}
|
||||
13
Task/Inheritance-Single/Ada/inheritance-single.ada
Normal file
13
Task/Inheritance-Single/Ada/inheritance-single.ada
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
package Inheritance is
|
||||
type Animal is tagged private;
|
||||
type Dog is new Animal with private;
|
||||
type Cat is new Animal with private;
|
||||
type Lab is new Dog with private;
|
||||
type Collie is new Dog with private;
|
||||
private
|
||||
type Animal is tagged null record;
|
||||
type Dog is new Animal with null record;
|
||||
type Cat is new Animal with null record;
|
||||
type Lab is new Dog with null record;
|
||||
type Collie is new Dog with null record;
|
||||
end Inheritance;
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
class Animal{
|
||||
//functions go here...
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
class Dog extends Animal {
|
||||
//functions go here...
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
class Cat extends Animal {
|
||||
//functions go here...
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
class Lab extends Dog {
|
||||
//functions go here...
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
class Collie extends Dog {
|
||||
//functions go here...
|
||||
}
|
||||
14
Task/Inheritance-Single/AmigaE/inheritance-single.amiga
Normal file
14
Task/Inheritance-Single/AmigaE/inheritance-single.amiga
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
OBJECT animal
|
||||
ENDOBJECT
|
||||
|
||||
OBJECT dog OF animal
|
||||
ENDOBJECT
|
||||
|
||||
OBJECT cat OF animal
|
||||
ENDOBJECT
|
||||
|
||||
OBJECT lab OF dog
|
||||
ENDOBJECT
|
||||
|
||||
OBJECT collie OF dog
|
||||
ENDOBJECT
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
script Animal
|
||||
end script
|
||||
|
||||
script Dog
|
||||
property parent : Animal
|
||||
end script
|
||||
|
||||
script Cat
|
||||
property parent : Animal
|
||||
end script
|
||||
|
||||
script Lab
|
||||
property parent : Dog
|
||||
end script
|
||||
|
||||
script Collie
|
||||
property parent : Dog
|
||||
end script
|
||||
14
Task/Inheritance-Single/AutoHotkey/inheritance-single.ahk
Normal file
14
Task/Inheritance-Single/AutoHotkey/inheritance-single.ahk
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
dog := new Collie
|
||||
MsgBox, % "A " dog.__Class " is a " dog.base.base.__Class " and is part of the " dog.kingdom " kingdom."
|
||||
|
||||
class Animal {
|
||||
static kingdom := "Animalia" ; Class variable
|
||||
}
|
||||
class Dog extends Animal {
|
||||
}
|
||||
class Cat extends Animal {
|
||||
}
|
||||
class Lab extends Dog {
|
||||
}
|
||||
class Collie extends Dog {
|
||||
}
|
||||
20
Task/Inheritance-Single/BBC-BASIC/inheritance-single.basic
Normal file
20
Task/Inheritance-Single/BBC-BASIC/inheritance-single.basic
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
INSTALL @lib$+"CLASSLIB"
|
||||
|
||||
DIM Animal{method}
|
||||
PROC_class(Animal{})
|
||||
|
||||
DIM Cat{method}
|
||||
PROC_inherit(Cat{}, Animal{})
|
||||
PROC_class(Cat{})
|
||||
|
||||
DIM Dog{method}
|
||||
PROC_inherit(Dog{}, Animal{})
|
||||
PROC_class(Dog{})
|
||||
|
||||
DIM Labrador{method}
|
||||
PROC_inherit(Labrador{}, Dog{})
|
||||
PROC_class(Labrador{})
|
||||
|
||||
DIM Collie{method}
|
||||
PROC_inherit(Collie{}, Dog{})
|
||||
PROC_class(Collie{})
|
||||
24
Task/Inheritance-Single/C++/inheritance-single.cpp
Normal file
24
Task/Inheritance-Single/C++/inheritance-single.cpp
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
class Animal
|
||||
{
|
||||
// ...
|
||||
};
|
||||
|
||||
class Dog: public Animal
|
||||
{
|
||||
// ...
|
||||
};
|
||||
|
||||
class Lab: public Dog
|
||||
{
|
||||
// ...
|
||||
};
|
||||
|
||||
class Collie: public Dog
|
||||
{
|
||||
// ...
|
||||
};
|
||||
|
||||
class Cat: public Animal
|
||||
{
|
||||
// ...
|
||||
};
|
||||
29
Task/Inheritance-Single/C-sharp/inheritance-single.cs
Normal file
29
Task/Inheritance-Single/C-sharp/inheritance-single.cs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
class Animal
|
||||
{
|
||||
/* ... */
|
||||
// ...
|
||||
}
|
||||
|
||||
class Dog : Animal
|
||||
{
|
||||
/* ... */
|
||||
// ...
|
||||
}
|
||||
|
||||
class Lab : Dog
|
||||
{
|
||||
/* ... */
|
||||
// ...
|
||||
}
|
||||
|
||||
class Collie : Dog
|
||||
{
|
||||
/* ... */
|
||||
// ...
|
||||
}
|
||||
|
||||
class Cat : Animal
|
||||
{
|
||||
/* ... */
|
||||
// ...
|
||||
}
|
||||
39
Task/Inheritance-Single/COBOL/inheritance-single.cobol
Normal file
39
Task/Inheritance-Single/COBOL/inheritance-single.cobol
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
CLASS-ID. Animal.
|
||||
*> ...
|
||||
END CLASS Animal.
|
||||
|
||||
CLASS-ID. Dog INHERITS Animal.
|
||||
ENVIRONMENT DIVISION.
|
||||
CONFIGURATION SECTION.
|
||||
REPOSITORY.
|
||||
CLASS Animal.
|
||||
|
||||
*> ...
|
||||
END CLASS Dog.
|
||||
|
||||
CLASS-ID. Cat INHERITS Animal.
|
||||
ENVIRONMENT DIVISION.
|
||||
CONFIGURATION SECTION.
|
||||
REPOSITORY.
|
||||
CLASS Animal.
|
||||
|
||||
*> ...
|
||||
END CLASS Cat.
|
||||
|
||||
CLASS-ID. Lab INHERITS Dog.
|
||||
ENVIRONMENT DIVISION.
|
||||
CONFIGURATION SECTION.
|
||||
REPOSITORY.
|
||||
CLASS Dog.
|
||||
|
||||
*> ...
|
||||
END CLASS Lab.
|
||||
|
||||
CLASS-ID. Collie INHERITS Dog.
|
||||
ENVIRONMENT DIVISION.
|
||||
CONFIGURATION SECTION.
|
||||
REPOSITORY.
|
||||
CLASS Dog.
|
||||
|
||||
*> ...
|
||||
END CLASS Collie.
|
||||
3
Task/Inheritance-Single/ChucK/inheritance-single-1.chuck
Normal file
3
Task/Inheritance-Single/ChucK/inheritance-single-1.chuck
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
public class Drums{
|
||||
//functions go here...
|
||||
}
|
||||
3
Task/Inheritance-Single/ChucK/inheritance-single-2.chuck
Normal file
3
Task/Inheritance-Single/ChucK/inheritance-single-2.chuck
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
public class LatinKit extends Drums{
|
||||
//functions go here...
|
||||
}
|
||||
3
Task/Inheritance-Single/ChucK/inheritance-single-3.chuck
Normal file
3
Task/Inheritance-Single/ChucK/inheritance-single-3.chuck
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
public class ElectronicKit extends Drums{
|
||||
//functions go here...
|
||||
}
|
||||
3
Task/Inheritance-Single/ChucK/inheritance-single-4.chuck
Normal file
3
Task/Inheritance-Single/ChucK/inheritance-single-4.chuck
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
public class Congas extends LatinKit{
|
||||
//functions go here...
|
||||
}
|
||||
3
Task/Inheritance-Single/ChucK/inheritance-single-5.chuck
Normal file
3
Task/Inheritance-Single/ChucK/inheritance-single-5.chuck
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
public class TechnoDrums extends ElectronicKit{
|
||||
//functions go here...
|
||||
}
|
||||
5
Task/Inheritance-Single/Clojure/inheritance-single-1.clj
Normal file
5
Task/Inheritance-Single/Clojure/inheritance-single-1.clj
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
(gen-class :name Animal)
|
||||
(gen-class :name Dog :extends Animal)
|
||||
(gen-class :name Cat :extends Animal)
|
||||
(gen-class :name Lab :extends Dog)
|
||||
(gen-class :name Collie :extends Dog)
|
||||
4
Task/Inheritance-Single/Clojure/inheritance-single-2.clj
Normal file
4
Task/Inheritance-Single/Clojure/inheritance-single-2.clj
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
(derive ::dog ::animal)
|
||||
(derive ::cat ::animal)
|
||||
(derive ::lab ::dog)
|
||||
(derive ::collie ::dog)
|
||||
6
Task/Inheritance-Single/Clojure/inheritance-single-3.clj
Normal file
6
Task/Inheritance-Single/Clojure/inheritance-single-3.clj
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
user> (isa? ::dog ::animal)
|
||||
true
|
||||
user> (isa? ::dog ::cat)
|
||||
false
|
||||
user> (isa? ::collie ::animal)
|
||||
true
|
||||
5
Task/Inheritance-Single/Coco/inheritance-single-1.coco
Normal file
5
Task/Inheritance-Single/Coco/inheritance-single-1.coco
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
class Animal
|
||||
class Cat extends Animal
|
||||
class Dog extends Animal
|
||||
class Lab extends Dog
|
||||
class Collie extends Dog
|
||||
28
Task/Inheritance-Single/Coco/inheritance-single-2.coco
Normal file
28
Task/Inheritance-Single/Coco/inheritance-single-2.coco
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
class Animal
|
||||
|
||||
(@name) ->
|
||||
|
||||
move: (meters) ->
|
||||
alert @name + " moved #{meters}m."
|
||||
|
||||
class Snake extends Animal
|
||||
|
||||
-> super ...
|
||||
|
||||
move: ->
|
||||
alert 'Slithering...'
|
||||
super 5
|
||||
|
||||
class Horse extends Animal
|
||||
|
||||
-> super ...
|
||||
|
||||
move: ->
|
||||
alert 'Galloping...'
|
||||
super 45
|
||||
|
||||
sam = new Snake 'Sammy the Python'
|
||||
tom = new Horse 'Tommy the Palomino'
|
||||
|
||||
sam.move!
|
||||
tom.move!
|
||||
33
Task/Inheritance-Single/Comal/inheritance-single.comal
Normal file
33
Task/Inheritance-Single/Comal/inheritance-single.comal
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
STRUC Animal
|
||||
DIM Species$ OF 20
|
||||
ENDSTRUC Animal
|
||||
|
||||
STRUC Dog
|
||||
INHERIT Animal
|
||||
DIM Race$ OF 20
|
||||
FUNC New CONSTRUCTOR
|
||||
Species$="Dog"
|
||||
ENDFUNC New
|
||||
ENDSTRUC Dog
|
||||
|
||||
STRUC Cat
|
||||
INHERIT Animal
|
||||
DIM Race$ OF 20
|
||||
FUNC New CONSTRUCTOR
|
||||
Species$="Cat"
|
||||
ENDFUNC New
|
||||
ENDSTRUC Cat
|
||||
|
||||
STRUC Lab
|
||||
INHERIT Dog
|
||||
FUNC New CONSTRUCTOR
|
||||
Race$:="Lab"
|
||||
ENDFUNC New
|
||||
ENDSTRUC Lab
|
||||
|
||||
STRUC Collie
|
||||
INHERIT Dog
|
||||
FUNC New CONSTRUCTOR
|
||||
Race$:="Collie"
|
||||
ENDFUNC New
|
||||
ENDSTRUC Collie
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
(defclass animal () ())
|
||||
(defclass dog (animal) ())
|
||||
(defclass lab (dog) ())
|
||||
(defclass collie (dog) ())
|
||||
(defclass cat (animal) ())
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
(defstruct animal)
|
||||
(defstruct (dog (:include animal)))
|
||||
(defstruct (lab (:include dog)))
|
||||
(defstruct (collie (:include dog)))
|
||||
(defstruct (cat (:include animal)))
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
;;; ASN.1 serialization logic specialized for animal class
|
||||
(defmethod serialize-to-asn-1 ((a animal))
|
||||
#| ... |#
|
||||
)
|
||||
|
||||
;;; casually introduce the method over strings too; no relation to animal
|
||||
(defmethod serialize-to-asn-1 ((s string))
|
||||
#| ... #|
|
||||
)
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
TYPE
|
||||
Animal = ABSTRACT RECORD (* *) END;
|
||||
Cat = RECORD (Animal) (* *) END; (* final record (cannot be extended) - by default *)
|
||||
Dog = EXTENSIBLE RECORD (Animal) (* *) END; (* extensible record *)
|
||||
Lab = RECORD (Dog) (* *) END;
|
||||
Collie = RECORD (Dog) (* *) END;
|
||||
21
Task/Inheritance-Single/D/inheritance-single.d
Normal file
21
Task/Inheritance-Single/D/inheritance-single.d
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
class Animal {
|
||||
// ...
|
||||
}
|
||||
|
||||
class Dog: Animal {
|
||||
// ...
|
||||
}
|
||||
|
||||
class Lab: Dog {
|
||||
// ...
|
||||
}
|
||||
|
||||
class Collie: Dog {
|
||||
// ...
|
||||
}
|
||||
|
||||
class Cat: Animal {
|
||||
// ...
|
||||
}
|
||||
|
||||
void main() {}
|
||||
12
Task/Inheritance-Single/DWScript/inheritance-single.dw
Normal file
12
Task/Inheritance-Single/DWScript/inheritance-single.dw
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
type
|
||||
Animal = class(TObject)
|
||||
private
|
||||
// private functions/variables
|
||||
public
|
||||
// public functions/variables
|
||||
end;
|
||||
|
||||
type Dog = class(Animal) end;
|
||||
type Cat = class(Animal) end;
|
||||
type Collie = class(Dog) end;
|
||||
type Lab = class(Dog) end;
|
||||
12
Task/Inheritance-Single/Delphi/inheritance-single.delphi
Normal file
12
Task/Inheritance-Single/Delphi/inheritance-single.delphi
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
type
|
||||
Animal = class(TObject)
|
||||
private
|
||||
// private functions/variables
|
||||
public
|
||||
// public functions/variables
|
||||
end;
|
||||
|
||||
Dog = class(Animal);
|
||||
Cat = class(Animal);
|
||||
Collie = class(Dog);
|
||||
Lab = class(Dog);
|
||||
18
Task/Inheritance-Single/E/inheritance-single-1.e
Normal file
18
Task/Inheritance-Single/E/inheritance-single-1.e
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
def makeType(label, superstamps) {
|
||||
def stamp {
|
||||
to audit(audition) {
|
||||
for s in superstamps { audition.ask(s) }
|
||||
return true
|
||||
}
|
||||
}
|
||||
def guard {
|
||||
to coerce(specimen, ejector) {
|
||||
if (__auditedBy(stamp, specimen)) {
|
||||
return specimen
|
||||
} else {
|
||||
throw.eject(ejector, `$specimen is not a $label`)
|
||||
}
|
||||
}
|
||||
}
|
||||
return [guard, stamp]
|
||||
}
|
||||
7
Task/Inheritance-Single/E/inheritance-single-2.e
Normal file
7
Task/Inheritance-Single/E/inheritance-single-2.e
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
def [Animal, AnimalStamp] := makeType("Animal", [])
|
||||
|
||||
def [Cat, CatStamp] := makeType("Cat", [AnimalStamp])
|
||||
def [Dog, DogStamp] := makeType("Dog", [AnimalStamp])
|
||||
|
||||
def [Lab, LabStamp] := makeType("Lab", [DogStamp])
|
||||
def [Collie, CollieStamp] := makeType("Collie", [DogStamp])
|
||||
3
Task/Inheritance-Single/E/inheritance-single-3.e
Normal file
3
Task/Inheritance-Single/E/inheritance-single-3.e
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
def fido implements LabStamp {}
|
||||
def tom implements CatStamp {}
|
||||
def brick {} # not an animal
|
||||
17
Task/Inheritance-Single/E/inheritance-single-4.e
Normal file
17
Task/Inheritance-Single/E/inheritance-single-4.e
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
? fido :Animal
|
||||
# value: <fido>
|
||||
|
||||
? fido :Cat
|
||||
# problem: <fido> is not a Cat
|
||||
|
||||
? fido :Lab
|
||||
# value: <fido>
|
||||
|
||||
? tom :Animal
|
||||
# value: <tom>
|
||||
|
||||
? tom :Cat
|
||||
# value: <tom>
|
||||
|
||||
? brick :Animal
|
||||
# problem: <brick> is not a Animal
|
||||
3
Task/Inheritance-Single/Eiffel/inheritance-single-1.e
Normal file
3
Task/Inheritance-Single/Eiffel/inheritance-single-1.e
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
class
|
||||
ANIMAL
|
||||
end
|
||||
5
Task/Inheritance-Single/Eiffel/inheritance-single-2.e
Normal file
5
Task/Inheritance-Single/Eiffel/inheritance-single-2.e
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
class
|
||||
DOG
|
||||
inherit
|
||||
ANIMAL
|
||||
end
|
||||
5
Task/Inheritance-Single/Eiffel/inheritance-single-3.e
Normal file
5
Task/Inheritance-Single/Eiffel/inheritance-single-3.e
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
class
|
||||
CAT
|
||||
inherit
|
||||
ANIMAL
|
||||
end
|
||||
5
Task/Inheritance-Single/Eiffel/inheritance-single-4.e
Normal file
5
Task/Inheritance-Single/Eiffel/inheritance-single-4.e
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
class
|
||||
LAB
|
||||
inherit
|
||||
DOG
|
||||
end
|
||||
5
Task/Inheritance-Single/Eiffel/inheritance-single-5.e
Normal file
5
Task/Inheritance-Single/Eiffel/inheritance-single-5.e
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
class
|
||||
COLLIE
|
||||
inherit
|
||||
DOG
|
||||
end
|
||||
24
Task/Inheritance-Single/Elena/inheritance-single.elena
Normal file
24
Task/Inheritance-Single/Elena/inheritance-single.elena
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
class Animal
|
||||
{
|
||||
// ...
|
||||
}
|
||||
|
||||
class Dog : Animal
|
||||
{
|
||||
// ...
|
||||
}
|
||||
|
||||
class Lab : Dog
|
||||
{
|
||||
// ...
|
||||
}
|
||||
|
||||
class Collie : Dog
|
||||
{
|
||||
// ...
|
||||
}
|
||||
|
||||
class Cat : Animal
|
||||
{
|
||||
// ...
|
||||
}
|
||||
15
Task/Inheritance-Single/F-Sharp/inheritance-single.fs
Normal file
15
Task/Inheritance-Single/F-Sharp/inheritance-single.fs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
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()
|
||||
5
Task/Inheritance-Single/Factor/inheritance-single.factor
Normal file
5
Task/Inheritance-Single/Factor/inheritance-single.factor
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
TUPLE: animal ;
|
||||
TUPLE: dog < animal ;
|
||||
TUPLE: cat < animal ;
|
||||
TUPLE: lab < dog ;
|
||||
TUPLE: collie < dog ;
|
||||
19
Task/Inheritance-Single/Fancy/inheritance-single.fancy
Normal file
19
Task/Inheritance-Single/Fancy/inheritance-single.fancy
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
class Animal {
|
||||
# ...
|
||||
}
|
||||
|
||||
class Dog : Animal {
|
||||
# ...
|
||||
}
|
||||
|
||||
class Cat : Animal {
|
||||
# ...
|
||||
}
|
||||
|
||||
class Lab : Dog {
|
||||
# ...
|
||||
}
|
||||
|
||||
class Collie : Dog {
|
||||
# ...
|
||||
}
|
||||
19
Task/Inheritance-Single/Fantom/inheritance-single.fantom
Normal file
19
Task/Inheritance-Single/Fantom/inheritance-single.fantom
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
class Animal
|
||||
{
|
||||
}
|
||||
|
||||
class Dog : Animal
|
||||
{
|
||||
}
|
||||
|
||||
class Cat : Animal
|
||||
{
|
||||
}
|
||||
|
||||
class Lab : Dog
|
||||
{
|
||||
}
|
||||
|
||||
class Collie : Dog
|
||||
{
|
||||
}
|
||||
7
Task/Inheritance-Single/Forth/inheritance-single-1.fth
Normal file
7
Task/Inheritance-Single/Forth/inheritance-single-1.fth
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
include 4pp/lib/foos.4pp
|
||||
|
||||
:: Animal class end-class {} ;
|
||||
:: Dog extends Animal end-extends {} ;
|
||||
:: Cat extends Animal end-extends {} ;
|
||||
:: Lab extends Dog end-extends {} ;
|
||||
:: Collie extends Dog end-extends {} ;
|
||||
7
Task/Inheritance-Single/Forth/inheritance-single-2.fth
Normal file
7
Task/Inheritance-Single/Forth/inheritance-single-2.fth
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
include FMS2LL.f
|
||||
|
||||
:class Animal ;class
|
||||
:class Dog <super Animal ;class
|
||||
:class Cat <super Animal ;class
|
||||
:class Lab <super Dog ;class
|
||||
:class Collie <super Dog ;class
|
||||
18
Task/Inheritance-Single/Fortran/inheritance-single.f
Normal file
18
Task/Inheritance-Single/Fortran/inheritance-single.f
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
module anim
|
||||
|
||||
type animal
|
||||
end type animal
|
||||
|
||||
type, extends(animal) :: dog
|
||||
end type dog
|
||||
|
||||
type, extends(animal) :: cat
|
||||
end type cat
|
||||
|
||||
type, extends(dog) :: lab
|
||||
end type lab
|
||||
|
||||
type, extends(dog) :: collie
|
||||
end type collie
|
||||
|
||||
end module anim
|
||||
21
Task/Inheritance-Single/FreeBASIC/inheritance-single.basic
Normal file
21
Task/Inheritance-Single/FreeBASIC/inheritance-single.basic
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
Type Animal Extends Object ' to enable virtual methods etc. if needed
|
||||
' ...
|
||||
End Type
|
||||
|
||||
Type Dog Extends Animal
|
||||
' ...
|
||||
End Type
|
||||
|
||||
Type Cat Extends Animal
|
||||
' ...
|
||||
End Type
|
||||
|
||||
Type Lab Extends Dog
|
||||
' ...
|
||||
End Type
|
||||
|
||||
Type Collie Extends Dog
|
||||
' ...
|
||||
End Type
|
||||
32
Task/Inheritance-Single/Go/inheritance-single.go
Normal file
32
Task/Inheritance-Single/Go/inheritance-single.go
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
package main
|
||||
|
||||
type animal struct {
|
||||
alive bool
|
||||
}
|
||||
|
||||
type dog struct {
|
||||
animal
|
||||
obedienceTrained bool
|
||||
}
|
||||
|
||||
type cat struct {
|
||||
animal
|
||||
litterBoxTrained bool
|
||||
}
|
||||
|
||||
type lab struct {
|
||||
dog
|
||||
color string
|
||||
}
|
||||
|
||||
type collie struct {
|
||||
dog
|
||||
catchesFrisbee bool
|
||||
}
|
||||
|
||||
func main() {
|
||||
var pet lab
|
||||
pet.alive = true
|
||||
pet.obedienceTrained = false
|
||||
pet.color = "yellow"
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
class Animal{
|
||||
//contents go here...
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
class Dog extends Animal{
|
||||
//contents go here...
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
class Cat extends Animal{
|
||||
//contents go here...
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
class Lab extends Dog{
|
||||
//contents go here...
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
class Collie extends Dog{
|
||||
//contents go here...
|
||||
}
|
||||
5
Task/Inheritance-Single/Haskell/inheritance-single.hs
Normal file
5
Task/Inheritance-Single/Haskell/inheritance-single.hs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
class Animal a
|
||||
class Animal a => Cat a
|
||||
class Animal a => Dog a
|
||||
class Dog a => Lab a
|
||||
class Dog a => Collie a
|
||||
3
Task/Inheritance-Single/Haxe/inheritance-single-1.haxe
Normal file
3
Task/Inheritance-Single/Haxe/inheritance-single-1.haxe
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
class Animal {
|
||||
// ...
|
||||
}
|
||||
3
Task/Inheritance-Single/Haxe/inheritance-single-2.haxe
Normal file
3
Task/Inheritance-Single/Haxe/inheritance-single-2.haxe
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
class Cat extends Animal {
|
||||
// ...
|
||||
}
|
||||
3
Task/Inheritance-Single/Haxe/inheritance-single-3.haxe
Normal file
3
Task/Inheritance-Single/Haxe/inheritance-single-3.haxe
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
class Dog extends Animal {
|
||||
// ...
|
||||
}
|
||||
3
Task/Inheritance-Single/Haxe/inheritance-single-4.haxe
Normal file
3
Task/Inheritance-Single/Haxe/inheritance-single-4.haxe
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
class Lab extends Dog {
|
||||
// ...
|
||||
}
|
||||
3
Task/Inheritance-Single/Haxe/inheritance-single-5.haxe
Normal file
3
Task/Inheritance-Single/Haxe/inheritance-single-5.haxe
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
class Collie extends Dog {
|
||||
// ...
|
||||
}
|
||||
14
Task/Inheritance-Single/Haxe/inheritance-single-6.haxe
Normal file
14
Task/Inheritance-Single/Haxe/inheritance-single-6.haxe
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
class Animal ()
|
||||
end
|
||||
|
||||
class Dog : Animal ()
|
||||
end
|
||||
|
||||
class Cat : Animal ()
|
||||
end
|
||||
|
||||
class Lab : Dog ()
|
||||
end
|
||||
|
||||
class Collie : Dog ()
|
||||
end
|
||||
5
Task/Inheritance-Single/Inform-7/inheritance-single.inf
Normal file
5
Task/Inheritance-Single/Inform-7/inheritance-single.inf
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
An animal is a kind of thing.
|
||||
A cat is a kind of animal.
|
||||
A dog is a kind of animal.
|
||||
A collie is a kind of dog.
|
||||
A lab is a kind of dog.
|
||||
5
Task/Inheritance-Single/Io/inheritance-single.io
Normal file
5
Task/Inheritance-Single/Io/inheritance-single.io
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
Animal := Object clone
|
||||
Cat := Animal clone
|
||||
Dog := Animal clone
|
||||
Collie := Dog clone
|
||||
Lab := Dog clone
|
||||
1
Task/Inheritance-Single/J/inheritance-single-1.j
Normal file
1
Task/Inheritance-Single/J/inheritance-single-1.j
Normal file
|
|
@ -0,0 +1 @@
|
|||
coclass 'Animal'
|
||||
2
Task/Inheritance-Single/J/inheritance-single-2.j
Normal file
2
Task/Inheritance-Single/J/inheritance-single-2.j
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
coclass 'Dog'
|
||||
coinsert 'Animal'
|
||||
2
Task/Inheritance-Single/J/inheritance-single-3.j
Normal file
2
Task/Inheritance-Single/J/inheritance-single-3.j
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
coclass 'Cat'
|
||||
coinsert 'Animal'
|
||||
2
Task/Inheritance-Single/J/inheritance-single-4.j
Normal file
2
Task/Inheritance-Single/J/inheritance-single-4.j
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
coclass 'Lab'
|
||||
coinsert 'Dog'
|
||||
2
Task/Inheritance-Single/J/inheritance-single-5.j
Normal file
2
Task/Inheritance-Single/J/inheritance-single-5.j
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
coclass 'Collie'
|
||||
coinsert 'Dog'
|
||||
4
Task/Inheritance-Single/J/inheritance-single-6.j
Normal file
4
Task/Inheritance-Single/J/inheritance-single-6.j
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
coinsert_Dog_ 'Animal'
|
||||
coinsert_Cat_ 'Animal'
|
||||
coinsert_Lab_ 'Dog'
|
||||
coinsert_Collie_ 'Dog'
|
||||
3
Task/Inheritance-Single/Java/inheritance-single-1.java
Normal file
3
Task/Inheritance-Single/Java/inheritance-single-1.java
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
public class Animal{
|
||||
//functions go here...
|
||||
}
|
||||
3
Task/Inheritance-Single/Java/inheritance-single-2.java
Normal file
3
Task/Inheritance-Single/Java/inheritance-single-2.java
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
public class Dog extends Animal{
|
||||
//functions go here...
|
||||
}
|
||||
3
Task/Inheritance-Single/Java/inheritance-single-3.java
Normal file
3
Task/Inheritance-Single/Java/inheritance-single-3.java
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
public class Cat extends Animal{
|
||||
//functions go here...
|
||||
}
|
||||
3
Task/Inheritance-Single/Java/inheritance-single-4.java
Normal file
3
Task/Inheritance-Single/Java/inheritance-single-4.java
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
public class Lab extends Dog{
|
||||
//functions go here...
|
||||
}
|
||||
3
Task/Inheritance-Single/Java/inheritance-single-5.java
Normal file
3
Task/Inheritance-Single/Java/inheritance-single-5.java
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
public class Collie extends Dog{
|
||||
//functions go here...
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
function Animal() {
|
||||
// ...
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
function Dog() {
|
||||
// ...
|
||||
}
|
||||
Dog.prototype = new Animal();
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
function Cat() {
|
||||
// ...
|
||||
}
|
||||
Cat.prototype = new Animal();
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
function Collie() {
|
||||
// ...
|
||||
}
|
||||
Collie.prototype = new Dog();
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
function Lab() {
|
||||
// ...
|
||||
}
|
||||
Lab.prototype = new Dog();
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
Animal.prototype.speak = function() {print("an animal makes a sound")};
|
||||
|
||||
var lab = new Lab();
|
||||
lab.speak(); // shows "an animal makes a sound"
|
||||
6
Task/Inheritance-Single/Julia/inheritance-single.julia
Normal file
6
Task/Inheritance-Single/Julia/inheritance-single.julia
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
abstract type Animal end
|
||||
abstract type Dog <: Animal end
|
||||
abstract type Cat <: Animal end
|
||||
|
||||
struct Lab <: Dog end
|
||||
struct Collie <: Dog end
|
||||
15
Task/Inheritance-Single/Kite/inheritance-single.kite
Normal file
15
Task/Inheritance-Single/Kite/inheritance-single.kite
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
class Animal [
|
||||
#Method goes here
|
||||
];
|
||||
|
||||
class Dog from Animal [
|
||||
#Method goes here
|
||||
];
|
||||
|
||||
class Lab from Dog [
|
||||
#Method goes here
|
||||
];
|
||||
|
||||
class collie from Dog [
|
||||
#Method goes here
|
||||
];
|
||||
32
Task/Inheritance-Single/Kotlin/inheritance-single.kotlin
Normal file
32
Task/Inheritance-Single/Kotlin/inheritance-single.kotlin
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
// version 1.0.6
|
||||
|
||||
open class Animal {
|
||||
override fun toString() = "animal"
|
||||
}
|
||||
|
||||
open class Dog : Animal() {
|
||||
override fun toString() = "dog"
|
||||
}
|
||||
|
||||
class Cat : Animal() {
|
||||
override fun toString() = "cat"
|
||||
}
|
||||
|
||||
class Labrador : Dog() {
|
||||
override fun toString() = "labrador"
|
||||
}
|
||||
|
||||
class Collie : Dog() {
|
||||
override fun toString() = "collie"
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val felix: Animal = Cat()
|
||||
val rover: Animal = Dog()
|
||||
val bella: Dog = Labrador()
|
||||
val casey: Dog = Collie()
|
||||
println("Felix is a $felix")
|
||||
println("Rover is a $rover")
|
||||
println("Bella is a $bella")
|
||||
println("Casey is a $casey")
|
||||
}
|
||||
24
Task/Inheritance-Single/Lasso/inheritance-single.lasso
Normal file
24
Task/Inheritance-Single/Lasso/inheritance-single.lasso
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
define animal => type {
|
||||
data public gender::string
|
||||
}
|
||||
|
||||
define dog => type {
|
||||
parent animal
|
||||
}
|
||||
|
||||
define cat => type {
|
||||
parent animal
|
||||
}
|
||||
|
||||
define collie => type {
|
||||
parent dog
|
||||
}
|
||||
|
||||
define lab => type {
|
||||
parent dog
|
||||
}
|
||||
|
||||
local(myanimal = lab)
|
||||
|
||||
#myanimal -> gender = 'Male'
|
||||
#myanimal -> gender
|
||||
19
Task/Inheritance-Single/Latitude/inheritance-single.latitude
Normal file
19
Task/Inheritance-Single/Latitude/inheritance-single.latitude
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
Animal ::= Object clone tap {
|
||||
;; Methods go here...
|
||||
}.
|
||||
|
||||
Dog ::= Animal clone tap {
|
||||
;; Methods go here...
|
||||
}.
|
||||
|
||||
Cat ::= Animal clone tap {
|
||||
;; Methods go here...
|
||||
}.
|
||||
|
||||
Lab ::= Dog clone tap {
|
||||
;; Methods go here...
|
||||
}.
|
||||
|
||||
Collie ::= Dog clone tap {
|
||||
;; Methods go here...
|
||||
}.
|
||||
2
Task/Inheritance-Single/Lingo/inheritance-single-1.lingo
Normal file
2
Task/Inheritance-Single/Lingo/inheritance-single-1.lingo
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
-- parent script "Animal"
|
||||
-- ...
|
||||
7
Task/Inheritance-Single/Lingo/inheritance-single-2.lingo
Normal file
7
Task/Inheritance-Single/Lingo/inheritance-single-2.lingo
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
-- parent script "Dog"
|
||||
property ancestor
|
||||
|
||||
on new (me)
|
||||
me.ancestor = script("Animal").new()
|
||||
return me
|
||||
end
|
||||
7
Task/Inheritance-Single/Lingo/inheritance-single-3.lingo
Normal file
7
Task/Inheritance-Single/Lingo/inheritance-single-3.lingo
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
-- parent script "Cat"
|
||||
property ancestor
|
||||
|
||||
on new (me)
|
||||
me.ancestor = script("Animal").new()
|
||||
return me
|
||||
end
|
||||
7
Task/Inheritance-Single/Lingo/inheritance-single-4.lingo
Normal file
7
Task/Inheritance-Single/Lingo/inheritance-single-4.lingo
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
-- parent script "Lab"
|
||||
property ancestor
|
||||
|
||||
on new (me)
|
||||
me.ancestor = script("Dog").new()
|
||||
return me
|
||||
end
|
||||
7
Task/Inheritance-Single/Lingo/inheritance-single-5.lingo
Normal file
7
Task/Inheritance-Single/Lingo/inheritance-single-5.lingo
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
-- parent script "Collie"
|
||||
property ancestor
|
||||
|
||||
on new (me)
|
||||
me.ancestor = script("Dog").new()
|
||||
return me
|
||||
end
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
Section Header
|
||||
+ name := ANIMAL;
|
||||
// ...
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue