-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyclass.java
More file actions
39 lines (39 loc) · 914 Bytes
/
Myclass.java
File metadata and controls
39 lines (39 loc) · 914 Bytes
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
abstract class Myclass {
abstract void calculate(double x);
}
class sub1 extends Myclass{
void calculate(double x)
{
System.out.println("Square = " + (x*x));
}
}
class sub2 extends Myclass{
void calculate(double x)
{
System.out.println("Square root = " + Math.sqrt(x));
}
}
class sub3 extends Myclass{
void calculate(double x)
{
System.out.println("Cubic = " + (x*x*x));
}
}
class Different
{
public static void main(String args[])
{
Myclass ref = new sub1();
ref.calculate(3);
ref= new sub2();
ref.calculate(4);
ref = new sub3();
ref.calculate(5);
// sub1 obj1 = new sub1();
// sub2 obj2 = new sub2();
// sub3 obj3 = new sub3();
// obj1.calculate(3);
// obj2.calculate(4);
// obj3.calculate(5);
}
}