-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example23.d
91 lines (76 loc) · 2.03 KB
/
example23.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import std.stdio;
import std.conv;
import std.math;
import std.random;
import std.datetime;
import std.algorithm;
import std.array;
import std.string;
import std.format;
import std.typecons : No;
import std.typecons;
import std.range : chain;
import std.file;
import core.thread;
import std.parallelism;
import std.concurrency;
import std.range;
void main() {
class Animal {
string name;
double height;
double weight;
string sound;
static int numOfAnimals;
this(string name, double height, double weight, string sound) {
this.name = name;
this.height = height;
this.weight = weight;
this.sound = sound;
numOfAnimals++;
}
void makeSound() {
writeln(this.name, " says ", this.sound);
}
void getInfo() {
writefln("%s is %.2f inches %.2f lbs and says %s",
this.name, this.height, this.weight, this.sound);
}
static void getNumOfAnimals() {
writeln("Num of Animals : ", numOfAnimals);
}
}
class Dog : Animal {
string owner;
this(string name, double height, double weight, string sound, string owner) {
super(name, height, weight, sound);
this.owner = owner;
}
override void getInfo() {
super.getInfo();
writefln("%s's owner is %s",
this.name, this.owner);
}
}
Animal jake = new Animal("Jake", 35, 140, "Woof");
jake.getInfo();
Dog paul = new Dog("Paul", 20, 85, "Grrr", "Robert Hansen");
paul.getInfo();
Animal john = new Dog("John", 20, 85, "Grrr", "Larry Eyler");
john.getInfo();
john.getNumOfAnimals();
interface Drivable {
void move();
void stop();
}
class Vehicle : Drivable {
void move() {}
void stop() {}
}
class Flyable {
abstract void fly() {
writeln("I'm flying");
}
abstract void crash();
}
}