-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathabstracting.java
33 lines (29 loc) · 922 Bytes
/
abstracting.java
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
//Here the use of abstract class is shown
//In abstract class if there is any abstract method defined then we have to redefine the same in the main class to
//ensure it's usage
abstract class sum
{
abstract void add();
int i = 10;
int j = 20;
void mul() //Not an abstract method hence no overriding is required
{
System.out.println("");
System.out.println("Invoking mthod of abstract class");
System.out.println("The multiplication of "+i+" and "+j+" is : "+(i*j));
}
}
class abstracting extends sum
{
public void add() //Abstract method so overriding in main class is required
{
System.out.println("Invoking members and method of abstract class after overriding");
System.out.println("The sum of "+i+" and "+j+" is: "+(i+j));
}
public static void main(String args[])
{
abstracting obj = new abstracting();
obj.add();
obj.mul();
}
}