forked from slgobinath/Java-Helps-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDoctorDemo.java
More file actions
51 lines (47 loc) · 1 KB
/
DoctorDemo.java
File metadata and controls
51 lines (47 loc) · 1 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
/**
* Sample code used to explain Object Oriented Programming.
*
* @version 1.0
* @author L.Gobinath
*/
public class DoctorDemo {
public static void main(String[] args) {
Cat cat = new Cat();
Dog dog = new Dog();
VeterinaryDoctor doctor = new VeterinaryDoctor();
cat.age = 4;
dog.age = 2;
doctor.treatCat(cat);
doctor.treatDog(dog);
}
}
class VeterinaryDoctor {
/**
* Give treatment to a cat.
* @param cat The cat.
*/
public void treatCat(Cat cat) {
if (cat.age < 3) {
System.out.println("Treatment C1");
} else {
System.out.println("Treatment C2");
}
}
/**
* Give treatment to a dog.
* @param dog The dog.
*/
public void treatDog(Dog dog) {
if (dog.age < 5) {
System.out.println("Treatment D1");
} else {
System.out.println("Treatment D2");
}
}
}
class Cat {
int age;
}
class Dog {
int age;
}