-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAbstractKeyword.java
More file actions
43 lines (33 loc) · 1.07 KB
/
AbstractKeyword.java
File metadata and controls
43 lines (33 loc) · 1.07 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
abstract class Human { // abstract class
// public abstract void eat(){ //abstract method
// System.out.println("om nom nom");
// }
public void walk() {
}
}
class Behaviour {
public void actLoud(Integer i) {
System.out.println("SHOUT NUMBER " + i + "!");
}
public void actLoud(Double i) { // Method overloading
System.out.println("SHOUT NUMBER " + i + "!");
}
// Number is superclass, and also Abstract and is being extension for Integer or
// Double (is more generic)
public void actLoud(Number i) { // Method overloading
System.out.println("SHOUT NUMBER " + i + "!");
}
}
class Man extends Human { // concrete class
public void eat() { // if we have class that extends abstract parent class we have to write the same
// methods.
}
}
public class AbstractKeyword {
public static void main(String[] args) {
Human obj = new Man(); // reference Human, but object Man
Behaviour obj1 = new Behaviour();
obj1.actLoud(5);
obj1.actLoud(6.7);
}
}