-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.java
83 lines (60 loc) · 1.68 KB
/
Solution.java
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
1. interface & abstract class
interface A{
final val (built-in default)
// abstract method, all methods declared here must be implemented by the classes that implements this class
void greetings()
}
abstract class B {
// 1. some lines of code you want to share among related classes
// 2. Define non-static, non-final vars
final var
non-final var
// implementation
}
C implements A
D extends B
*/
import java.io.*;
abstract class University {
String name = "";
University(String name) { this.name = name; }
// default non-abstract methods
public void introduction() {
System.out.println("name intro: " + this.name);
}
//abstract methods declaration
abstract public void greetings();
}
class Department extends University {
int size;
String department_name = "";
Department(String name, String department_name, int size) {
super(name);
this.size = size;
this.department_name = department_name;
}
@Override
public void greetings() {
System.out.println("University: " + this.name + ", Department: " + this.department_name + ", size: " + this.size);
}
}
interface Animal {
// abstract method
int size = 2;
void greetings();
}
class Cat implements Animal {
String name = "";
Cat(String name) { this.name = name; }
@Override
public void greetings() { System.out.println("Cat: " + this.name + " miao~"); }
}
class Solution {
public static void main(String[] args) {
Solution s = new Solution();
Department d = new Department("Umich", "EECS", 1000);
d.introduction();
d.greetings();
}
}