-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDog.java
More file actions
57 lines (47 loc) · 1.38 KB
/
Copy pathDog.java
File metadata and controls
57 lines (47 loc) · 1.38 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
51
52
53
54
55
56
57
/* Write a Java program to create a class called "Dog" with a name and breed attribute. Create two instances
of the "Dog" class, set their attributes using the constructor and modify the attributes using the setter methods
and print the updated values. */
public class Dog {
private String name;
private String breed;
// constructor
public Dog(String name, String breed){
this.name = name;
this.breed = breed;
}
// setter
public void setName(String name){
this.name = name;
}
public void setBreed(String breed){
this.breed = breed;
}
// getter
public String getName(){
return name;
}
public String getBreed(){
return breed;
}
// method
public void printValues(){
System.out.println("Dog Name: " + getName());
System.out.println("Dog Breed: " + getBreed());
}
}
class Dogimp{
public static void main(String[] args) {
Dog dog1 = new Dog("German", "Golden Retriever");
Dog dog2 = new Dog("Sheperd", "Husky");
dog1.printValues();
System.out.println("Updated dog1 info");
dog1.setName("Tommy");
dog1.setBreed("Pitbull");
dog1.printValues();
dog2.printValues();
System.out.println("Updated dog2 info");
dog2.setName("Bella");
dog2.setBreed("Pug");
dog2.printValues();
}
}