-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabsClass.java
More file actions
61 lines (58 loc) · 1.57 KB
/
absClass.java
File metadata and controls
61 lines (58 loc) · 1.57 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
public class absClass {
public static void main(String[]args)
{
//abstract= abstraction(hiding implementation)
// cant be instantiated directly i.e. cant create object for this class
// abstract method can be created inside a abstract clas but it should be implemented
// concrete methods inside a abstract class is by default inherited by classes extended from abs class
//color c= new color() will show error becoz obj cant be created of abs class
blue b=new blue();
green g= new green();
red r= new red();
b.disp();
g.disp();
r.disp();
System.out.println(b.use());
System.out.println(g.use());
System.out.println(r.use());
}
}
// created a abs class color
abstract class color{
//an abs method
abstract String use();
// concrete method inehrited by default by chile classes
void disp()
{
System.out.println(this.getClass().getSimpleName()+"-This is a color");
//getClass()-- returns runtime class for current obj
//getSimpleName()--returns name of class without package
}
}
class blue extends color
{
// abs method implemented
@Override
String use()
{
return "blue is sky";
}
}
class green extends color
{
// abs method implemented
@Override
String use()
{
return "green is grass";
}
}
class red extends color
{
// abs method implemented
@Override
String use()
{
return "red is blood";
}
}