-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathabstractclass.java
More file actions
35 lines (31 loc) · 1 KB
/
abstractclass.java
File metadata and controls
35 lines (31 loc) · 1 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
package abstractClass;
import mypackage.Package;
// non-abstract class extends abstract class.
// it is necessary to define all the abstract method's body by overriding them in the concrete class
public class abstractclass extends abclass {
public static void main(String[] args) {
abstractclass ab = new abstractclass();
Package p = new Package();
p.welcome();
ab.abm();
ab.show();
ab.sum();
// abstract class data members are accessed using objects of concrete sub class.
System.out.println("abstract class data member m =" + ab.m);
p.bye();
// objects of abstract classes can not be created but references can be created with concrete subclass.
// abstraction can be achieved this way.
abclass abc = new abstractclass();
abc.abm();
abc.hello();
}
// Overrides all the abstract methods from the parent classes
@Override
public void abm() {
System.out.println("abstract method overriden with a body");
}
@Override
void hello() {
System.out.println("hello method");
}
}