- Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtutorial_30.java
More file actions
Latest commit
50 lines (42 loc) · 1.09 KB
/
Copy pathtutorial_30.java
File metadata and controls
50 lines (42 loc) · 1.09 KB
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
/**
* Driver class
*/
classPetStore {
publicstaticvoidmain(String[] args) {
// create an instance of our Dog class using our three different constructors
Doglab1 = newDog();
Doglab2 = newDog("Mike", "brown", true);
Doglab3 = newDog("Barker");
}
}
/**
* Dog class
*/
classDog {
privateStringname;
privateStringcolor;
privateintage;
privatedoubleheight;
privatebooleanmale;
// by default constructor will set everything to null, 0, or false
publicDog() {
name = "";
color = "";
age = 0;
height = 0.5;
male = true;
}
publicDog(Stringn, Stringc, booleang) {
name = n;
color = c;
age = 0; // optional because it will automatically set primitive data types to zero
height = 0.5;
male = g;
}
publicDog(Stringname) {
/* need to specify which variable is from your class
and which one is the argument using the 'this' keyword
*/
this.name = name;
}
}