-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_22_abstract_class.java
More file actions
58 lines (54 loc) · 1.44 KB
/
Copy path_22_abstract_class.java
File metadata and controls
58 lines (54 loc) · 1.44 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
// we can't make object in abstract class but we can make refference variable.
// a class which contain the abstract keyword in its declaration is called abstract class.
// we can not make object.
//abstract class _22_abstract_class {
//}
//class la{
// public static void main(String[] args) {
// _22_abstract_class r = new _22_abstract_class(); // error - _22_abstract_class is abstract; cannot be instantiated.
// }
//}
// but we make reference
//abstract class _22_abstract_class {
//}
//class Dog extends _22_abstract_class{
//
//}
//class la{
// public static void main(String[] args) {
// _22_abstract_class r = new Dog();
// }
//}
// it may or may not contain abstract methords.
// it can have abstract and non abstract methord.
// to use an abstract class , you have to inherite it from sub classes.
// abstract program
abstract class animal{
animal(){
System.out.println("All animals ....!");
}
public abstract void sound();
}
class dog extends animal{
dog(){
super();
}
public void sound(){
System.out.println("Dog is Barking");
}
}
class lion extends animal{
lion() {
super();
}
public void sound(){
System.out.println("Lion is Roar");
}
}
class tes{
public static void main(String[] args) {
dog d = new dog();
lion l = new lion();
d.sound(); l.sound();
}
}