-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetterandSetter.java
More file actions
46 lines (33 loc) · 896 Bytes
/
GetterandSetter.java
File metadata and controls
46 lines (33 loc) · 896 Bytes
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
import java.util.*;
public class GetterandSetter {
public static void main(String[] args) {
Animal a1 = new Animal();
Scanner sc = new Scanner(System.in);
System.out.print("Enter Animal Name: ");
String name = sc.nextLine();
System.out.print("Enter Animal Color: ");
String color = sc.nextLine();
a1.setName(name);
a1.setColor(color);
a1.display();
}
}
class Animal {
String name;
String color;
public String getName(String name) {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getColor(String color) {
return color;
}
public void setColor(String color) {
this.color = color;
}
public void display() {
System.out.println("Animal Name: " + name + "\n" + " Color: " + color);
}
}