-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
26 lines (24 loc) · 718 Bytes
/
Main.java
File metadata and controls
26 lines (24 loc) · 718 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
package leetcode;
public class Main {
public static void main(String[] args) {
Fruit[] fruit = new Apple[10];
fruit[0] = new Apple();
fruit[1] = new Jonathan();
try {
fruit[0] = new Fruit();
System.out.println("add fruit in index 0");
}catch (Exception e){
System.out.println("cant put fruit in index 0");
}
try {
fruit[0] = new Orange();
System.out.println("add orange in index 0");
}catch (Exception e){
System.out.println("cant put orange in index 0");
}
}
}
class Fruit{}
class Apple extends Fruit{}
class Jonathan extends Apple{}
class Orange extends Fruit{}