-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCCINHEREx1.java
More file actions
63 lines (46 loc) · 1.46 KB
/
CCINHEREx1.java
File metadata and controls
63 lines (46 loc) · 1.46 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
58
59
60
61
62
63
// INHERRITANCE CODING CHALLENGE 1
// Ex 01
// step 1 Create a class named animal
// Add a filed called name of type string
// Add a filed called age of type int
// Add a method called makesound() that print "Animal makes a sound"
class Animal {
String name;
int age;
void makesound() {
System.out.println("Animal makes a Sound");
}
}
// Step 2 Create a Subclass named Dog that inherits form Animal
// Add a filed called bread of type String
// Override the makesSOund() method to print "Dog Bark"
// Add a method called fetch() that to print "Dog is Fetching"
class Dog extends Animal{
String bread;
@Override
void makesound(){
System.out.println("Dog Barks");
}
void fetch(){
System.out.println("Dog is Fecthing");
}
}
public class CCINHEREx1 {
public static void main(String[] args) {
Animal cat = new Animal();
cat.name = "Simba";
cat.age = 4;
Dog d1 = new Dog();
d1.name = "Kalli";
d1.bread = "Kow Kow";
d1.age = 6;
System.out.println(cat.name);
System.out.println(cat.age);
cat.makesound();
System.out.println();
System.out.println(d1.name);
System.out.println(d1.age);
System.out.println(d1.bread);
d1.makesound();
}
}