-
Notifications
You must be signed in to change notification settings - Fork 124
Expand file tree
/
Copy pathLearningAbstraction.java
More file actions
97 lines (50 loc) · 972 Bytes
/
LearningAbstraction.java
File metadata and controls
97 lines (50 loc) · 972 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
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
package javaOOPS2;
public class LearningAbstraction {
public static void main(String[] args) {
Employee obj = new Employee();
Person pObj = obj;
LivingBeing lObj = obj;
Vehicle v1 = new Scooty();
}
}
// using abstract keyword
abstract class ElectronicItem {
abstract void battery();
}
abstract class Vehicle {
abstract void starts();
void breaks() { // cannot achieve true abstraction
System.out.println("vehicle breaks");
}
}
class Scooty extends Vehicle {
@Override
void starts() {
}
}
class Car extends Vehicle {
@Override
void starts() {
}
}
// using Interfaces
interface Person {
void walk();
}
interface LivingBeing {
void walk();
void breaths();
}
class Employee implements Person, LivingBeing {
@Override
public void walk() {
}
public void breaths() {
// TODO Auto-generated method stub
}
}
class Student implements Person {
@Override
public void walk() {
}
}