-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfruit.java
More file actions
50 lines (40 loc) · 1.12 KB
/
fruit.java
File metadata and controls
50 lines (40 loc) · 1.12 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
class name {
String name, taste;
int size;
// overridden
void eat() {
name = "fruit_name";
taste = "fruit_taste";
System.out.println(name + "from name class");
System.out.println(taste + "from name class");
}
}
class Apple extends name {
// override
void eat() {
name = "Apple";
taste = "Sweet";
System.out.println(name);
System.out.println(taste);
}
}
class Orange extends name {
// override
void eat() {
name = "Orange";
taste = "sour";
System.out.println(name);
System.out.println(taste);
}
}
public class fruit extends Orange{
// Create a base class Fruit with name ,taste and size as
// its attributes. Create a method called eat() which describes
// the name of the fruit and its taste. Inherit the same in 2 other
// classes Apple and Orange and override the eat() method to
// represent each fruit taste
public static void main(String[] args) {
fruit obj = new fruit();
obj.eat();
}
}