-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathabclass.java
More file actions
36 lines (30 loc) · 1.08 KB
/
abclass.java
File metadata and controls
36 lines (30 loc) · 1.08 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
package abstractClass;
// an abstract class inheriting another abstract class.
// abstract class is a class declared with the abstract keyword.
// it can hold both abstract as well as non-abstract(concrete) methods.
abstract class abclass extends baclass {
int m = 5, n;
// constructor of abstract class
// abstract class can have constructor but cannot be instantiated i.e. it cannot create objects of its own.
abclass() {
System.out.println("constructor from abstract class invoked");
}
// abstract method in abstract class.
public abstract void abm();
// concrete method in abstract class.
public void show() {
System.out.println("non abstract method inside abstract class");
}
void sum() {
System.out.println("enter both the numbers:");
java.util.Scanner sc = new java.util.Scanner(System.in);
m = sc.nextInt();
n = sc.nextInt();
sc.close();
System.out.println("sum: " + (m + n));
}
// overrides abstract method from parent class but doesn't define its body.
// its body can be defined in the concrete class inherits this class.
@Override
abstract void hello();
}