Anonymous user
Inheritance/Single: Difference between revisions
m
Fixed lang tags.
m (→{{header|J}}) |
m (Fixed lang tags.) |
||
Line 33:
<lang actionscript>public class Animal {
// ...
}
<lang actionscript>public class Cat extends Animal {
// ...
}
<lang actionscript>public class Dog extends Animal {
// ...
}
<lang actionscript>public class Lab extends Dog {
// ...
}
<lang actionscript>public class Collie extends Dog {
// ...
}
=={{header|Ada}}==
Line 60:
type Lab is new Dog with null record;
type Collie is new Dog with null record;
end Inheritance;
=={{header|C++}}==
<lang cpp>class Animal
Line 85:
{
// ...
};
== {{header|Common Lisp}} ==
Line 230:
<lang haxe>class Animal {
// ...
}
<lang haxe>class Cat extends Animal {
// ...
}
<lang haxe>class Dog extends Animal {
// ...
}
<lang haxe>class Lab extends Dog {
// ...
}
<lang haxe>class Collie extends Dog {
// ...
}
=={{header|Io}}==
=={{header|J}}==
Line 325:
<lang Lisaac>Section Header
+ name := ANIMAL;
// ...
<lang Lisaac>Section Header
+ name := CAT;
Section Inherit
- parent : ANIMAL := ANIMAL;
// ...
<lang Lisaac>Section Header
+ name := DOG;
Section Inherit
- parent : ANIMAL := ANIMAL;
// ...
<lang Lisaac>Section Header
+ name := LAB;
Section Inherit
- parent : DOG := DOG;
// ...
<lang Lisaac>Section Header
+ name := COLLIE;
Section Inherit
- parent : DOG := DOG;
// ...
=={{header|Objective-C}}==
Line 381:
}
// ...
@end
=={{header|OCaml}}==
Line 440:
=={{header|PHP}}==
<lang
// functions go here...
}
Line 533:
Inheritance is implemented by setting the object's class attribute with a character vector.
<lang R>aCollie <- "woof"
class(aCollie) <- c("Collie", "Dog", "Animal")
===S4===
Inheritance is implemented by using the 'contains' argument in setClass
Line 540:
setClass("Cat", representation(), prototype(), contains="Animal")
setClass("Collie", representation(), prototype(), contains="Dog")
setClass("Lab", representation(), prototype(), contains="Dog")
=={{header|Ruby}}==
Line 579:
define: #Cat &parents: {Animal}.
define: #Lab &parents: {Dog}.
define: #Collie &parents: {Dog}.
=={{header|Smalltalk}}==
This is an example of the object serialization format used by many varieties of Smalltalk. Normally the class tree would be defined and navigated via a class browser within a graphical Smalltalk environment.
<lang smalltalk>
"* etc. *" !▼
!Animal subclass: #Cat▼
"* etc. *" !
=={{header|Tcl}}==
Line 635:
dog = new(pet)
fido = new(dog)
felix = new(cat)
{{Omit From|ALGOL 68}} <!-- it isn't immediately obvious that ALGOL 68 is object oriented -->
|