forked from codehouseindia/Java-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstract_Class_Example.java
More file actions
137 lines (104 loc) · 2.01 KB
/
Abstract_Class_Example.java
File metadata and controls
137 lines (104 loc) · 2.01 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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//Subscribed by Mritunjay Kumar
//https://www.facebook.com/Mritunjay70/posts/1445812775628125
abstract class Person {
String name;
int age;
Person() {
}
Person(String n, int r) {
name = n;
age = r;
}
void setData(String name1, int age1)
{
name = name1;
age = age1;
}
void printDetails()
{
System.out.print("Name: "+name+" Age: "+age);
}
abstract void exceptional();
final void isAdult() {
if (age > 18) System.out.println("\t Yes");
}
} // class Person ends
class Student extends Person
{
double cpi;
Student() {
}
Student(String n, int r, double c) {
super(n, r);
cpi = c;
}
void setData(String name1, int age1, double cpi1)
{
super.setData(name1, age1);
cpi = cpi1;
}
void printDetails()
{
System.out.println();
super.printDetails();
System.out.print(" CPI: "+cpi);
}
void f() {
}
void exceptional()
{
if (cpi > 9.5) System.out.print(" Exceptional ");
}
void isAdult(Person p) {
}
} // class Student ends here
abstract class test extends Student {
abstract void f();
void f2(){
}
}
class Faculty extends Person
{
float noOfPub;
Faculty() {
}
Faculty(String n, int r, float nop) {
super(n, r);
noOfPub = nop;
}
void setData(String name1, int age1, int nop)
{
super.setData(name1, age1);
noOfPub = nop;
}
void printDetails()
{
System.out.println();
super.printDetails();
System.out.print(" No of Pub: "+noOfPub);
}
void exceptional()
{
if (noOfPub > 100) System.out.print(" Exceptional ");
}
}
public class AbstractDemo {
public static void main(String[] args)
{
Student s1 = new Student(), s2 = new Student();
Faculty f1 = new Faculty(), f2 = new Faculty();
s1.setData("A", 10, 9.7); s2.setData("B", 10, 7.0);
f1.setData("C", 70, 300); f2.setData("D", 75, 50);
Person [] p= new Person[4];
p[0] = s1;
p[1] = s2;
p[2] = f1;
p[3] = f2;
for (int index=0; index<p.length; index++)
{
p[index].printDetails();
p[index].exceptional();
p[index].isAdult();
}
}
}