Inheritance/Single: Difference between revisions

m
Fixed lang tags.
m (Fixed lang tags.)
Line 33:
<lang actionscript>public class Animal {
// ...
} </lang>
<lang actionscript>public class Cat extends Animal {
// ...
} </lang>
<lang actionscript>public class Dog extends Animal {
// ...
} </lang>
<lang actionscript>public class Lab extends Dog {
// ...
} </lang>
<lang actionscript>public class Collie extends Dog {
// ...
} </lang>
 
=={{header|Ada}}==
Line 60:
type Lab is new Dog with null record;
type Collie is new Dog with null record;
end Inheritance; </lang>
=={{header|C++}}==
<lang cpp>class Animal
Line 85:
{
// ...
}; </lang>
 
== {{header|Common Lisp}} ==
Line 230:
<lang haxe>class Animal {
// ...
} </lang>
<lang haxe>class Cat extends Animal {
// ...
} </lang>
<lang haxe>class Dog extends Animal {
// ...
} </lang>
<lang haxe>class Lab extends Dog {
// ...
} </lang>
<lang haxe>class Collie extends Dog {
// ...
} </lang>
 
=={{header|Io}}==
 
<lang io>Animal := Object clone
Cat := Animal clone
Dog := Animal clone
Collie := Dog clone
Lab := Dog clone</lang>
 
=={{header|J}}==
Line 325:
<lang Lisaac>Section Header
+ name := ANIMAL;
// ... </lang>
<lang Lisaac>Section Header
+ name := CAT;
Section Inherit
- parent : ANIMAL := ANIMAL;
// ... </lang>
<lang Lisaac>Section Header
+ name := DOG;
Section Inherit
- parent : ANIMAL := ANIMAL;
// ... </lang>
<lang Lisaac>Section Header
+ name := LAB;
Section Inherit
- parent : DOG := DOG;
// ... </lang>
<lang Lisaac>Section Header
+ name := COLLIE;
Section Inherit
- parent : DOG := DOG;
// ... </lang>
 
=={{header|Objective-C}}==
Line 381:
}
// ...
@end </lang>
 
=={{header|OCaml}}==
Line 440:
 
=={{header|PHP}}==
<lang rubyphp>class Animal {
// 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") </lang>
===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") </lang>
 
=={{header|Ruby}}==
Line 579:
define: #Cat &parents: {Animal}.
define: #Lab &parents: {Dog}.
define: #Collie &parents: {Dog}. </lang>
 
=={{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> Object subclass: #Animal
instanceVariableNames: ' ' "* space separated list of names *"
classVariableNames: ' '
poolDictionaries: ' '
category: ' ' !
 
"* declare methods here, separated with '!' *"
"* !Animal methodsFor: 'a category'! *"
"* methodName *"
"* method body! !
 
!Animal subclass: #Dog
"* etc. *" !
!Animal subclass: #Cat
"* etc. *" !
 
!DogAnimal subclass: #LabCat
"* etc. *" !
 
!Dog subclass: #CollieLab
"* etc. *" !</lang>
 
!AnimalDog subclass: #CatCollie
"* etc. *" !</lang>
 
=={{header|Tcl}}==
Line 635:
dog = new(pet)
fido = new(dog)
felix = new(cat) </lang>
 
{{Omit From|ALGOL 68}} <!-- it isn't immediately obvious that ALGOL 68 is object oriented -->
Anonymous user